这是我的python代码。
from aiohttp import web
if __name__ == "__main__":
app = web.Application()
cors = aiohttp_cors.setup(app)
app.on_shutdown.append(on_shutdown)
app.router.add_get("/", index)
app.router.add_get("/client.js", javascript)
cors = aiohttp_cors.setup(app, defaults={
"*": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers="*",
allow_headers="*",
)
})
resource = cors.add(app.router.add_resource("/offer"))
cors.add(resource.add_route("POST", offer))
resource = cors.add(app.router.add_resource("/image_makeup"))
cors.add(resource.add_route("POST", image_makeup))
web.run_app(
app, access_log=None, host=args.host, port=args.port, ssl_context=ssl_context
)命令:
gunicorn main:app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker错误:
[2020-10-17 21:17:13 +0530] [47676] [INFO] Starting gunicorn 20.0.4
[2020-10-17 21:17:13 +0530] [47676] [INFO] Listening at: http://127.0.0.1:8080 (47676)
[2020-10-17 21:17:13 +0530] [47676] [INFO] Using worker: sync
[2020-10-17 21:17:13 +0530] [47678] [INFO] Booting worker with pid: 47678
usage: gunicorn [-h] [--cert-file CERT_FILE] [--key-file KEY_FILE] [--host HOST] [--port PORT] [--verbose]
gunicorn: error: unrecognized arguments: --bind localhost:8080 wsgi:main
[2020-10-17 21:17:18 +0530] [47678] [INFO] Worker exiting (pid: 47678)
[2020-10-17 21:17:19 +0530] [47680] [INFO] Booting worker with pid: 47680我的根目录中有main.py,但我仍然收到上面的错误。请看一下我哪里弄错了。
发布于 2020-10-17 23:56:20
由于您没有直接运行文件"main.py",因此变量__name__的值不是__main__,而是main。您需要更改您的if语句:
if __name__ == "main":
app = web.Application()
...发布于 2020-10-19 11:31:02
作为给定的in the documentation,
在运行Gunicorn时,您需要提供模块的名称(在本例中为main )和应用程序或应用程序工厂的名称,以及作为命令行标志或在配置文件中提供的其他Gunicorn设置。
入口点可以是应用程序实例,也可以是不接受参数并返回应用程序实例的协程
你的代码必须是这样的:
from aiohttp import web
async def my_web_app():
app = web.Application()
....
return app或
from aiohttp import web
my_web_app = web.Application()
....Gunicorn命令变为:
gunicorn main:my_web_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorkerhttps://stackoverflow.com/questions/64404263
复制相似问题