I am trying to include IPv6 in a Python 2 application and I am having problems. Whenever I try to bind to an IPv6 socket, a socket.error: getsockaddrarg: bad family exception is socket.error: getsockaddrarg: bad family . I can reproduce the error simply:
import socket s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.bind(('', 12345))
This code works fine if I run in Python 3. Unfortunately, the script will require significant porting work to work in Python 3, and I would rather not do it yet.
Is there something I need to do to make IPv6 work in Python 2 or am I SOL?
More: Python 2.6.2 (r262: 71600, October 24, 2009, 03:16:31) [GCC 4.4.1 [gcc-4_4-revision branch 150839]] on linux2 (this is Python, which is part of the standard openSUSE 11.2 installation) .
Update
After AndiDog helped me figure out that socket.AF_INET6 was detected, even if IPv6 was not configured, I discovered socket.has_ipv6 . This is defined as logical and indicates whether Python was created with IPv6.
source share