Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x Sanic:request.ip和request.remote\u addr之间的区别?_Python 3.x_Http_Request_Ip_Sanic - Fatal编程技术网

Python 3.x Sanic:request.ip和request.remote\u addr之间的区别?

Python 3.x Sanic:request.ip和request.remote\u addr之间的区别?,python-3.x,http,request,ip,sanic,Python 3.x,Http,Request,Ip,Sanic,Sanic请求的ip和远程地址属性之间有什么区别 源代码: 某些代理或负载平衡器可能隐藏原始客户端ip。提到的标题可以存储此值 例如,请参阅头文件。ip仅显示直接连接Sanic的地址,而请求。remote\u addr仅显示代理提供的远程地址(例如,如果您是)。您需要根据应用程序是否在代理后运行来选择一个。要支持两者,请使用 user\u ip=request.remote\u addr或request.ip @property def ip(self): """ :retur

Sanic请求的ip和远程地址属性之间有什么区别

源代码:


某些代理或负载平衡器可能隐藏原始客户端ip。提到的标题可以存储此值


例如,请参阅头文件。ip仅显示直接连接Sanic的地址,而
请求。remote\u addr
仅显示代理提供的远程地址(例如,如果您是)。您需要根据应用程序是否在代理后运行来选择一个。要支持两者,请使用

user\u ip=request.remote\u addr或request.ip
@property
def ip(self):
    """
    :return: peer ip of the socket
    """
    if not hasattr(self, "_socket"):
        self._get_address()
    return self._ip


@property
def remote_addr(self):
    """Attempt to return the original client ip based on `forwarded`,
    `x-forwarded-for` or `x-real-ip`. If HTTP headers are unavailable or
    untrusted, returns an empty string.

    :return: original client ip.
    """
    if not hasattr(self, "_remote_addr"):
        self._remote_addr = self.forwarded.get("for", "")
    return self._remote_addr