使用python在Windows XP中创建IPv6套接字

时间:2011-11-22 16:04:44

标签: python sockets windows-xp python-3.x ipv6

以下代码适用于Windows7和Linux,但在Windows XP中出现错误:

import socket
print(socket.has_ipv6)
print("INET=",socket.AF_INET,"\nINET6=",socket.AF_INET6,"\nDGRAM=",socket.SOCK_DGRAM)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) #Error in XP

这是Windows XP中的输出:

Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import socket
>>> print(socket.has_ipv6)
True
>>>
>>> print("INET=",socket.AF_INET,"\nINET6=",socket.AF_INET6,"\nDGRAM=",socket.SOCK_DGRAM)
INET= 2
INET6= 23
DGRAM= 2
>>>
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s
<socket.socket object, fd=1840, family=2, type=2, proto=0>
>>>
>>>
>>> s6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python32\lib\socket.py", line 94, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
socket.error: [Errno 10047] An address incompatible with the requested protocol was used
>>>
>>>

为什么我会收到此错误,我该如何解决此问题?

1 个答案:

答案 0 :(得分:2)

需要在您的计算机上安装IPv6。 Instructions are here.(谢谢大卫)