You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
barneygale opened this issue
Nov 21, 2024
· 2 comments
Labels
3.12bugs and security fixes3.13bugs and security fixes3.14new features, bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
When a file: URL is given to urllib.request.urlopen(), it returns an addinfourl object. This object's url attribute (and its deprecated geturl() method) usually return incorrect results. For example:
>>>fromurllib.requestimporturlopen>>>urlopen('file:Doc/requirements.txt').url'file://Doc/requirements.txt'# expected: 'file:Doc/requirements.txt'>>>urlopen('file:C:/requirements.txt').url'file://C:/requirements.txt'# expected: 'file:C:/requirements.txt' or 'file:///C:/requirements.txt'
The code always prepends file://, but this might be too many slashes or too few depending on the path's drive and root.
The original `file:` URL that was passed to `urlopen()` is now used as the
`url` attribute of the returned `addinfourl` object. The `addinfourl.url`
attribute *always* reflects the original `file:`, `data:` or `ftp:` URL
now.
3.12bugs and security fixes3.13bugs and security fixes3.14new features, bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
Bug report
Bug description:
When a
file:
URL is given tourllib.request.urlopen()
, it returns anaddinfourl
object. This object'surl
attribute (and its deprecatedgeturl()
method) usually return incorrect results. For example:The code always prepends
file://
, but this might be too many slashes or too few depending on the path's drive and root.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
urllib.response.addinfourl.url
value for openedfile:
URIs #127091The text was updated successfully, but these errors were encountered: