majek / puka

Puka - the opinionated RabbitMQ client
https://github.com/majek/puka
Other
182 stars 34 forks source link

client.connect fails with "getsockaddrarg: bad family" #27

Closed schmir closed 11 years ago

schmir commented 11 years ago

The following code

import puka

client = puka.Client("amqp://localhost/")
client.wait(client.connect())

fails on my system with

Traceback (most recent call last):
  File "s.py", line 4, in 
    client.wait(client.connect())
  File "/home/ralf/puka/puka/client.py", line 19, in wrapper
    p = method(*args, **kwargs)
  File "/home/ralf/puka/puka/client.py", line 48, in connect
    return self._connect()
  File "/home/ralf/puka/puka/connection.py", line 81, in _connect
    self.sd.connect(sockaddr)
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: getsockaddrarg: bad family

The problem is I have IPv6 disabled in my python installation, but puka decides to use IPv6 addresses if it can resolve them.

puka shouldn't ask for IPv6 addresses if it can't use them later. You can use socket.has_ipv6 to check if python supports IPv6.

majek commented 11 years ago

So your localhost resolves to ipv6 but your python has ipv6 disabled. No surprise puka is confused :)

majek commented 11 years ago

Can you run this patch and check if it's sufficient?

schmir commented 11 years ago

yes, that solves it. thanks!

why does puka prefer IPv6 addresses? python's socket.create_connection tries IPv4 addresses first...

majek commented 11 years ago

No particular reason. Both choices (ipv4 vs ipv6 first) are wrong, so it should make no difference.

I'm glad the patch works!