[Twisted-Python] Queries about connecting to a XML-RPC server over IPv6

Phil Mayers p.mayers at imperial.ac.uk
Thu Dec 12 05:33:21 MST 2013


On 12/12/13 12:23, Amit Saha wrote:
>
>
> ----- Original Message -----
>> From: "Amit Saha" <asaha at redhat.com>
>> To: "Twisted general discussion" <twisted-python at twistedmatrix.com>
>> Sent: Tuesday, December 10, 2013 11:59:27 AM
>> Subject: Re: [Twisted-Python] Queries about connecting to a XML-RPC server over IPv6
>>
>>
>>
>> ----- Original Message -----
>>> From: "Phil Mayers" <p.mayers at imperial.ac.uk>
>>> To: twisted-python at twistedmatrix.com
>>> Sent: Monday, December 9, 2013 7:33:17 PM
>>> Subject: Re: [Twisted-Python] Queries about connecting to a XML-RPC server
>>> over IPv6
>>>
>>> On 09/12/13 05:28, Amit Saha wrote:
>>>
>>>> proxy = Proxy('http://localhost6:8000')
>>>> proxy.callRemote('my_proxy_method').addCallbacks(printValue, printError)
>>>>
>>>>
>>>> When I run it, i get "No route to host: 101, Network is unreachable".
>>>>
>>>> However, 'curl -6 localhost:8000' succeeds. What could be going on here?
>>>
>>> The IPv6 support in Twisted is very new - check your version even *has*
>>> it - and it's still a work in progress. You might find that you can't do
>>> this. I'd have to read the code to be sure and I don't have time right
>>> now, but my guess is that t.w.xmlrpc isn't "getaddrinfo"-ised so won't
>>> connect to IPv6 names.
>>>
>>> If your version of Twisted supports it, you could probably work around
>>> this by sub-classing Proxy and calling reactor.connectTCP('::1', 8000)
>>> to attach the protocol yourself.
>>
>> Thanks for your reply, Phil. So, I basically modified twisted/web/xmlrpc.py
>> so that
>> when it was calling connectTCP(), i substituted '::1' in place of self.host
>> and yes the method is called successfully.
>>
>> I will consider your other hints and see if there is an easy way to work
>> around this
>> in my particular use case.
>
> I finally ended up doing this:

Just to point out this is obviously a pretty hackish way of doing it; 
for starters, getaddrinfo() is blocking, so you should use deferToThread 
at minimum.

You might want to look at:

http://twistedmatrix.com/trac/browser/tags/releases/twisted-13.2.0/twisted/internet/endpoints.py#L707

...for inspiration.



More information about the Twisted-Python mailing list