2010-10-09 80 views
3

爲什麼ipv6連接失敗?爲什麼python的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') 

回答

6

鏈路本地地址(例如fe80 :: whatever)通常需要指定工作範圍ID。嘗試

sa = ('fe80::21b:78ff:fe30:7c6%en0', 2000, 0, 0) 

改爲。 (如果您試圖連接()的計算機可通過en0以外的網絡接口訪問,請使用en0所在接口的名稱替換)

+0

注意:已經給出此答案,現在我發現以上技術不適合我。 :^(詳情在這裏:http://stackoverflow.com/questions/4030269/why-doesnt-a-en0-suffix-work-to-connect-a-link-local-ipv6-tcp-socket-in-python – 2010-10-27 05:56:35