问题描述
我正在尝试在Python中将自定义Transport类与xmlrpclib一起使用,但是当我指定自定义Transport时,在第一次调用时确实出现了异常:
I am trying to use a custom Transport class with xmlrpclib in Python but when I specify a custom Transport, I do get an exception at the first call:
File "/Users/sorins/dev/py/confluence/confluence/confluence.py", line 208, in __init__
self._token = self._server.confluence1.login(username, password)
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
TypeError: unbound method request() must be called with SafeTransport instance as first argument (got str instance instead)
示例代码:
#!/usr/bin/env python
from xmlrpclib import Transport
class MyTransport(Transport):
pass
server = xmlrpclib.ServerProxy('https://example.com/rpc/xmlrpc',allow_none=True,transport=MyTransport)
server.confluence1.login(username, password) # <-- exception
已建立原始连接,但第一次调用RPC方法将失败,并出现上述错误.
The original connection is made but the first call to RPC method will fail with the above error.
删除transport = MyTransport解决了该问题.
Removing the transport=MyTransport solves the problem.
注意:我对SafeTransport进行了相同的尝试,并获得了相同的结果.
Note: I tried the same with SafeTransport and same result.
我确实需要自定义传输方式才能注入一些标头.我该如何解决?
I do need a custom transport in order to inject some headers. How do I fix this?
推荐答案
更改为transport=MyTransport()
,而不是类型,而是此类型的实例.
change to transport=MyTransport()
, not the type, but an instance of this type.
这篇关于由于TypeError无法将自定义Transport类与python xmlrpclib一起使用:未绑定的方法request()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!