Reading a client's header from Python CGI script?

前端 未结 4 2145
我在风中等你
我在风中等你 2021-02-12 20:21

I\'m writing a very simple web service, written in Python and run as CGI on an Apache server.

According to Python docs (somewhere... I forgot where), I can use sys.stdin

4条回答
  •  滥情空心
    2021-02-12 20:28

    If you are running as a CGI, you can't read the HTTP header directly, but the web server put much of that information into environment variables for you. You can just pick it out of os.environ[]

    The list of environment variables that might be there is pretty long. You can find it by doing a web search for "common gateway interface". For example, in http://www.ietf.org/rfc/rfc3875.txt they are called "meta-variables".

提交回复
热议问题