Reputation: 937
I'm trying to run a flask application with gunicorn. I'm in the process of understanding how gunicorn works, and this is the thing I am not understanding. I have the following code with a function I am running:
from flask import Flask, request, make_response
app = Flask(__name__)
@app.route('/')
def index():
content = "Hello World"
fwd_for = "X-Forwarded-For: {}".format(
request.headers.get('x-forwarded-for', None)
)
real_ip = "X-Real-IP: {}".format(
request.headers.get('x-real-ip', None)
)
fwd_proto = "X-Forwarded-Proto: {}".format(
request.headers.get('x-forwarded-proto', None)
)
output = "\n".join([content, fwd_for, real_ip, fwd_proto])
response = make_response(output, 200)
response.headers["Content-Type"] = "text/plain"
return response
I am running the following gunicorn command: gunicorn -w 4 app:index
After it starts, I'm getting an Internal Server Error
and am presented with the following TypeError:
TypeError: index() takes 0 positional arguments but 2 were given
To my knowledge, I am not passing in any arguments or parameters but am still getting this. Any advice on how I can fix this would be helpful.
Upvotes: 1
Views: 2040
Reputation: 1
Maybe this can help you.
gunicorn --worker-class gevent app:app
Upvotes: 0
Reputation: 7656
The launch command gunicorn -w 4 app:index
aims for the index
function within app.py
.
You need to point it at the app
object within app.py
so:
gunicorn -w 4 app:app
Upvotes: 1