Why the connect failed for ipv6 at python?

烂漫一生 提交于 2019-12-10 19:34:51

问题


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')

回答1:


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)  

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)



来源:https://stackoverflow.com/questions/3895570/why-the-connect-failed-for-ipv6-at-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!