【问题标题】:How to catch request information in the python twisted xmlrpc_method?如何在 python twisted xmlrpc_method 中捕获请求信息?
【发布时间】:2013-06-01 18:09:27
【问题描述】:

我研究了扭曲的 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()

【问题讨论】:

    标签: python twisted xml-rpc


    【解决方案1】:

    我自己没有使用过 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

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 2011-03-26
      • 1970-01-01
      • 2014-06-16
      • 2016-09-20
      • 1970-01-01
      • 2021-11-29
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多