Reading a client's header from Python CGI script?

前端 未结 4 648
南旧
南旧 2021-02-12 20:17

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:24

    These are given to the CGI script through the environment:

    import os
    user_agent = os.environ["HTTP_USER_AGENT"]
    ip = os.environ["REMOTE_ADDR"]
    

提交回复
热议问题