为什么python的ipv6连接失败? [英] Why the connect failed for ipv6 at python?
本文介绍了为什么python的ipv6连接失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么ipv6连接失败?
Why the connect failed for ipv6 ??
# python
>>> import socket
>>> s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
>>> sa = ('2000::1',2000,0,0)
>>> s.connect(sa)
>>> sa = ('fe80::21b:78ff:fe30:7c6', 2000, 0, 0)
>>> s.connect(sa)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in connect
socket.error: (22, 'Invalid argument')
推荐答案
链接本地地址(例如fe80 :: whatever)通常需要指定作用域ID才能起作用。尝试
Link-local addresses (e.g. fe80::whatever) typically require a scope id to be specified in order to work. Try
sa = ('fe80::21b:78ff:fe30:7c6%en0', 2000, 0, 0)
。 (如果您要连接的计算机可以通过en0以外的网络接口访问,请替换为en0现在所在的接口的名称)
instead. (If the computer you're trying to connect() to is accessible via a network interface other than en0, substitute in the name of the interface where en0 is now)
这篇关于为什么python的ipv6连接失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文