The problem is that create_connection did a getaddrinfo, and then when sock.connect(),
there is another getaddrinfo in _socketcommon._resolve_addr(self._sock, address),
the second getaddrinfo lost the IPv6 scope id, then Invalid argument error occurred.
The text was updated successfully, but these errors were encountered:
The scope identifier is dropped, that's true and I think has been for some time (though it's not documented IIRC). I can reproduce that on a multi-homed host on macOS with Python 3.x and 2.7. (Here, en7 and en10 are two interfaces with two different local IPs. When the scope ID works, the created sockets have different local IPs. When it doesn't, they have the same local IP.)
>>> import socket
>>> import gevent.socket as gsocket
# Try to connect to google.com
>>> s7 = socket.create_connection(('2607:f8b0:4000:80e::200e%en7', 80))
>>> s10 = socket.create_connection(('2607:f8b0:4000:80e::200e%en10', 80))
>>> s7.getsockname(), s10.getsockname() # Different local IPs :)
(('...:7441', 61130, 0, 0),
('...:297c', 61131, 0, 0))
>>> gs7 = gsocket.create_connection(('2607:f8b0:4000:80e::200e%en7', 80))
>>> gs10 = gsocket.create_connection(('2607:f8b0:4000:80e::200e%en10', 80))
>>> gs7.getsockname(), gs10.getsockname() # Same local IP :(
(('...:297c', 61153, 0, 0),
('...:297c', 61154, 0, 0))
(Writing tests for it that run in all environments might be tricky without mocking some things…)
I couldn't figure out where an Invalid argument would come from, though…until I actually looked more closely at the IP address you're using. D'oh, it's link-local. On my system, that results in Errno 65 No route to host.
Note that some resolvers (c-ares for sure) don't support scope IDs at all.
Thanks for your response!
yes, it's a link-local, that's why the scope identifier is required. You can connect to google.com through its global unicast address with or without a scope identifier, maybe you should try to connect to a local network sevice through its link-local address.