Skip to content

GET Requests to link-local IPv6 addresses don't work on Python 3.7+ #4554

Closed
@mjonuschat

Description

🐞 Describe the bug
The aiohttp resolver loses information related to linklocal IPv6 addresses on Python 3.7+ due to a changes in the representation returned by socket.getaddrinfo()

💡 To Reproduce
Try to get an URL like http://[fe80::1%eth0]:8080/, it will result in an OSError (Invalid argument) exception.

This seems to be due to the way that scopeid's are handled in resolver.py:

Run socket.getaddrinfo('fe80::1%eth0', 8080, family=socket.AF_INET6, proto=socket.IPPROTO_TCP)[0][4] on python 3.6:

socket.getaddrinfo('fe80::1%eth0', 8080, family=socket.AF_INET6, proto=socket.IPPROTO_TCP)[0][4]
>>> socket.getaddrinfo('fe80::1%eth0', 8080, family=socket.AF_INET6, proto=socket.IPPROTO_TCP)[0][4]
('fe80::1%eth0', 8080, 0, 4)

Run it on python 3.7:

>>> socket.getaddrinfo('fe80::1%eth0', 8080, family=socket.AF_INET6, proto=socket.IPPROTO_TCP)[0][4]
('fe80::1', 8080, 0, 4)y

The address element of the tuple no longer includes the textual representation of the scope id, it's only contained in the matching scope_id element of the tuple - which then is missing when later callings _loop.create_connection().

💡 Expected behavior
The URL is successfully retrieved for link local IPv6 addresses.

📋 Logs/tracebacks

N/A

📋 Your version of the Python

$ python3 --version
Python 3.6.6
$ python3.7 --version
Python 3.7.5

📋 Your version of the aiohttp/yarl/multidict distributions

$ python -m pip show aiohttp
python -m pip show aiohttp
Name: aiohttp
Version: 3.6.2
$ python -m pip show multidict
Name: multidict
Version: 4.7.4
$ python -m pip show yarl
Name: yarl
Version: 1.4.2

📋 Additional context
OS: Centos7 Linux
Proxy Server: No
Related to: client

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions