英文:
Docker python app can't find `PATH_INFO` env variable
问题
I'm trying to run python backend using Docker, however app can't find PATH_INFO
environment variable. Though on another machine it works well, difference is OS version: previous is ubuntu 21.04
and current is ubuntu 22.04
The error is caused by this piece of code:
path = environ.get("PATH_INFO", "/").lower()
here environ is a dict containing all env variables
App is running using docker-compose
which creates contianer, where ENTRYPOINT
includes docker_entry
file:
import bjoern
from index import app
bjoern.run(app, '0.0.0.0', 80)
where app
is
if __name__ == "__main__":
wsgiref.handlers.CGIHandler().run(app)
英文:
I'm trying to run python backend using Docker, however app can't find PATH_INFO
environment variable. Though on another machine it works well, difference is OS version: previous is ubuntu 21.04
and current is ubuntu 22.04
The error is caused by this piece of code:
path = environ.get("PATH_INFO", "/").lower()
here environ is a dict containing all env variables
App is running using docker-compose
which creates contianer, where ENTRYPOINT
includes docker_entry
file:
import bjoern
from index import app
bjoern.run(app, '0.0.0.0', 80)
where app
is
if __name__ == "__main__":
wsgiref.handlers.CGIHandler().run(app)
答案1
得分: 1
PATH_INFO
必须在脚本执行期间设置,它不是操作系统上默认可用的变量。你可以尝试在启动脚本之前或脚本内部打印出所有环境变量。
# bash
env
# python
import os
print(os.environ)
编辑:你可能会假设 Nginx 会为你的脚本设置 PATH_INFO
,就像它为 PHP FPM 一样。但实际上并不会。
英文:
PATH_INFO
must be set during your script execution, it is not a default variable available on the OS. You likely can try printing out all the env variables before starting your script or inside it.
# bash
env
# python
import os
print(os.environ)
edit: you might be assuming nginx sets PATH_INFO
for your script, like it does for PHP FPM. It is not.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论