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

发布于 2024-12-17 06:18:43 字数 1356 浏览 2 评论 0原文

以下代码可在 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
>>>
>>>

为什么我会收到此错误,如何修复此错误?

The following piece of code works on Windows7 and Linux, but gives an Error in 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

This is the output in 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
>>>
>>>

Why do i get this Error, and how can i fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2024-12-24 06:18:43

您的计算机上需要安装 IPv6。 说明位于此处。(谢谢,David)

IPv6 needs to be installed on your machine. Instructions are here. (Thanks, David)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文