问题
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)
Sample code:
#!/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
The original connection is made but the first call to RPC method will fail with the above error.
Removing the transport=MyTransport solves the problem.
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?
回答1:
change to transport=MyTransport()
, not the type, but an instance of this type.
来源:https://stackoverflow.com/questions/17569519/unable-to-use-custom-transport-class-with-python-xmlrpclib-due-to-typeerror-unb