python - 运行python脚本时出现gunicorn错误
问题描述
这是我的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 仍然出现上述错误。请看看我在哪里犯了错误。
解决方案
由于您没有直接运行文件“main.py”,因此变量的值__name__
不是__main__
but main
。你需要改变你的if
陈述:
if __name__ == "main":
app = web.Application()
...
推荐阅读
- python - 是什么导致 http 请求覆盖由 file.write() 创建的内部缓冲区?
- vb.net - 背景图片移动 vb.net
- php - 如何在 Laravel 5.6 中使用车辆 user_id 打印用户电子邮件
- mongodb - Mongo DB 聚合管道
- firebase - 通过firebase auth添加图片等数据
- std - 具有均值和方差的 pypsark randn
- c++ - 为什么指向函数的指针等于1?
- linux - Vala DBus 接口对象我应该如何注册属性更改?
- traefik - 从 CLI 覆盖后端 url 以代理到主机
- c++ - 如何检测哪个应用程序在 Delphi 中执行我的程序?