Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python获取客户端ip_Python_Apache_Webserver_Mod Python - Fatal编程技术网

使用python获取客户端ip

使用python获取客户端ip,python,apache,webserver,mod-python,Python,Apache,Webserver,Mod Python,我是python的新手。 我想写一个简单的网页,在屏幕上打印客户端ip 我的http.conf处理程序: AddHandler mod_python.py PythonHandler mod_python.publisher 蟒蛇 cgi.escape(os.environ[“REMOTE\u ADDR”])返回此错误:KeyError:'REMOTE\u ADDR' 我只是迷路了BaseHTTPRequestHandler 那么,获取客户端ip的简单方法是什么? 谢谢。好的,我找到了答案: f

我是python的新手。 我想写一个简单的网页,在屏幕上打印客户端ip

我的http.conf处理程序: AddHandler mod_python.py PythonHandler mod_python.publisher 蟒蛇

cgi.escape(os.environ[“REMOTE\u ADDR”])返回此错误:KeyError:'REMOTE\u ADDR' 我只是迷路了BaseHTTPRequestHandler 那么,获取客户端ip的简单方法是什么?
谢谢。

好的,我找到了答案:

from mod_python import apache
def client_ip(req):
    req.add_common_vars()
    return req.subprocess_env['REMOTE_ADDR']

它起作用了

如果您担心可伸缩性,这可能会快一点:

from mod_python import apache
req.get_remote_host(apache.REMOTE_NOLOOKUP)