Unable to use custom Transport class with python xmlrpclib due to TypeError: unbound method request()

廉价感情. 提交于 2019-12-12 03:53:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!