This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ipaddress module fails on rfc4007 scoped IPv6 addresses
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: asvetlov Nosy List: Jeremy McMillan, asvetlov, lisroach, mic4ael, miss-islington, ncoghlan, ohwgiles, opavlyuk, pmoody, terry.reedy, xtreak
Priority: normal Keywords: patch

Created on 2018-09-24 14:30 by Jeremy McMillan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13772 merged opavlyuk, 2019-06-03 08:57
PR 25824 open ohwgiles, 2021-05-02 22:00
Messages (10)
msg326240 - (view) Author: Jeremy McMillan (Jeremy McMillan) Date: 2018-09-24 14:30
ipaddress module has no support for scoped IPv6 addresses which prevents the use of ipaddress.ip_address() and ipaddress.IPv6Address() with (always available by default on IPv6 systems) RFC conforming IPv6 link local addresses that specify interface scope.

This is bad because interface scope is required for connect() and bind() operations on multihomed machines, and virtualized or software defined networking will make this case very common.


>>> ipaddress.IPv6Address('fe80::dead:dead:beef:ffff')
>>> ipaddress.IPv6Address('fe80::dead:dead:beef:ffff%eth0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 1900, in __init__
    self._ip = self._ip_int_from_string(addr_str)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 1716, in _ip_int_from_string
    raise AddressValueError("%s in %r" % (exc, ip_str)) from None
ipaddress.AddressValueError: Only hex digits permitted in 'ffff%eth0' in 'fe80::dead:dead:beef:ffff%eth0'
>>> ipaddress.IPv6Interface('fe80::dead:dead:beef:ffff%eth0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 2060, in __init__
    IPv6Address.__init__(self, addr[0])
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 1900, in __init__
    self._ip = self._ip_int_from_string(addr_str)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/", line 1716, in _ip_int_from_string
    raise AddressValueError("%s in %r" % (exc, ip_str)) from None
ipaddress.AddressValueError: Only hex digits permitted in 'ffff%eth0' in 'fe80::dead:dead:beef:ffff%eth0'
msg326312 - (view) Author: Jeremy McMillan (Jeremy McMillan) Date: 2018-09-25 02:34
subclass workaround implementation example
msg328960 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2018-10-30 23:49
I think this is something that would be good to have. Jeremy would you care to make a PR for this?
msg339928 - (view) Author: Michal (mic4ael) Date: 2019-04-11 06:21
I would like to fix this problem if nobody is against that. I stumbled upon the very same thing recently and I think it would be a nice opportunity to contribute.
msg339978 - (view) Author: Jeremy McMillan (Jeremy McMillan) Date: 2019-04-11 14:11
I think the code in SaltStack to handle scoped IPv6 addresses is mature, so please look at these examples.
msg347186 - (view) Author: Oleksandr Pavliuk (opavlyuk) * Date: 2019-07-03 07:41
Pull request needs a review.
msg347976 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-07-15 16:05
FWIW: Marking Component: Documentation means that the issue is only about changing the doc.  Hence the auto-assignment to the nebulous docs group, which no longer exists in the form it once did.  Enhancement issues nearly always need a doc change but are not marked 'Documentation'.  I am not sure what Jeremy's original intent was, but the actual PR is mostly code implementing and testing the newly documented addition.
msg348893 - (view) Author: Oleksandr Pavliuk (opavlyuk) * Date: 2019-08-02 08:29
Please, pay attention to this issue. Pull request needs core review.
msg361358 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-02-04 16:34
Nick, can you comment on this and review the revised PR?
msg362693 - (view) Author: miss-islington (miss-islington) Date: 2020-02-26 14:34
New changeset 21da76d1f1b527d62b2e9ef79dd9aa514d996341 by opavlyuk in branch 'master':
bpo-34788: Add support for scoped IPv6 addresses (GH-13772)
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 78969
2021-05-02 22:00:23ohwgilessetnosy: + ohwgiles

pull_requests: + pull_request24512
2020-02-26 14:43:17asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-02-26 14:34:01miss-islingtonsetnosy: + miss-islington
messages: + msg362693
2020-02-11 10:06:19asvetlovsetassignee: asvetlov

nosy: + asvetlov
2020-02-04 16:34:02terry.reedysetnosy: + ncoghlan

messages: + msg361358
versions: - Python 2.7
2019-08-02 08:29:47opavlyuksetmessages: + msg348893
2019-07-15 16:05:08terry.reedysetversions: + Python 3.9, - Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
nosy: + terry.reedy, - docs@python
messages: + msg347976

assignee: docs@python -> (no value)
components: - Documentation
type: behavior -> enhancement
2019-07-03 07:41:11opavlyuksetnosy: + opavlyuk
messages: + msg347186
2019-06-03 08:57:17opavlyuksetkeywords: + patch
stage: patch review
pull_requests: + pull_request13657
2019-04-11 14:11:50Jeremy McMillansetmessages: + msg339978
2019-04-11 06:21:37mic4aelsetnosy: + mic4ael
messages: + msg339928
2018-10-30 23:49:36lisroachsetnosy: + lisroach
messages: + msg328960
2018-09-25 02:34:31Jeremy McMillansetmessages: + msg326312
2018-09-24 16:30:09xtreaksetnosy: + xtreak
2018-09-24 16:05:00yselivanovsetnosy: + pmoody
2018-09-24 14:30:02Jeremy McMillancreate