gpt4 book ai didi

python - 无法使用 sys.argv --bind 运行 Gunicorn

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:58 25 4
gpt4 key购买 nike

我需要从 python 脚本为应用程序启动 Gunicorn,并尝试运行 gunicorn --bind 0.0.0.0:5000 tito.wsgi:application。我尝试过以下方法:

import sys

sys.argv = ['--gunicorn']

sys.argv.append("--bind 0.0.0.0:5000")
sys.argv.append("myapp.execute:application")


WSGIApplication(
usage="%(prog)s [OPTIONS] [APP_MODULE]"
).run()

这最终会出现以下错误:

File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named '--bind 0'

如果我运行为:

sys.argv = ['--gunicorn --bind 0.0.0.0:5000'] 

它不会获取 --bind 参数这不需要 --bind 选项。如何使用 --bind 0.0.0.0:5000 作为参数来运行它?

最佳答案

这个 sys.argv.append("-b 0.0.0.0:5000") 成功了。似乎它已将 --bind 识别为模块

关于python - 无法使用 sys.argv --bind 运行 Gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58967809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com