我正在尝试使用gunicorn 运行烧瓶应用程序。我正在了解gunicorn如何工作,这是我不明白的事情。我有以下代码和我正在运行的函数:
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
我正在运行以下gunicorn命令:
gunicorn -w 4 app:index
启动后,我收到一个
Internal Server Error
并出现以下类型错误:
TypeError: index() takes 0 positional arguments but 2 were given
据我所知,我没有传递任何参数或参数,但仍然得到这个。任何有关如何解决此问题的建议都会很有帮助。
启动命令
gunicorn -w 4 app:index
的目标是index
内的app.py
功能。
您需要将其指向
app
内的 app.py
对象,因此:
gunicorn -w 4 app:app
也许这可以帮助你。 Gunicorn --worker-class gevent app:app