Python SimpleXMLRPCServer 中客户端的 IP 地址?
I have a SimpleXMLRPCServer server (Python).
How can I get the IP address of the client in the request handler?
This information appears in the log. However, I am not sure how to access this information from within the request handler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Michael 指出的,您可以从请求处理程序中获取
client_address
。例如,您可以重写从BaseRequestHandler
间接继承的__init__
函数。As Michael noted, you can get
client_address
from within the request handler. For instance, you can override the__init__
function which is inherited indirectly fromBaseRequestHandler
.请求处理程序本身应该有一个属性
client_address
(继承自BaseHTTPRequestHandler
)。来自 BaseHTTPRequestHandler:The request handler itself should have a property
client_address
(inherited fromBaseHTTPRequestHandler
). From BaseHTTPRequestHandler:将 IP 地址传递给请求方法的一种方法是重写 RequestHandler.decode_request_content。
decode_request_content 返回一个 XML 字符串。
示例:
只需在其中插入另一个参数即可。
并相应地更新您的方法签名。
One way to pass the ip address to the request method is to override RequestHandler.decode_request_content.
decode_request_content returns a XML string.
Example:
Just slip another parameter in there.
and update your method signatures accordingly.