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

1

0

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?

Shaina answered 10/7, 2013 at 11:30 Comment(0)
C
1

change to transport=MyTransport(), not the type, but an instance of this type.

Camphor answered 6/5, 2014 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.