Skip to main content
 首页 » 编程设计

python之如何在 python twisted xmlrpc_method 中捕获请求信息

2024年11月01日7落叶无声

我研究了扭曲的 xmlrpc 教程:http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html设置用于构建我的 xmlrpc 方法的 xmlrpc 服务器,但我想知道来自客户端的一些请求信息,如 ip 地址。教程只是告诉我添加 xmlrpc_ 作为前缀使我的方法成为远程过程调用。有谁知道如何重写它?任何帮助将不胜感激。或者我可能需要强制客户端将其 ip 作为参数发送?

def xmlrpc_some_method(self): 
  if request.ip in bad_ips(): 
    return '404' 
  else: 
    return do_something() 

请您参考如下方法:

我自己没有使用过 xmlrpc 但通过查看源代码 [1],看起来你可以用 t.w.x.withRequest [2] 修饰函数然后你会得到 request 作为函数的第一个参数。

[1] http://twistedmatrix.com/trac/browser/tags/releases/twisted-13.0.0/twisted/web/xmlrpc.py#L169

[2] http://twistedmatrix.com/trac/browser/tags/releases/twisted-13.0.0/twisted/web/xmlrpc.py#L37