Docker的Python应用找不到`PATH_INFO`环境变量。

huangapple go评论56阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月27日 11:49:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定