Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urllib.request.urlopen('file:...').url incorrect value #127090

Open
barneygale opened this issue Nov 21, 2024 · 2 comments
Open

urllib.request.urlopen('file:...').url incorrect value #127090

barneygale opened this issue Nov 21, 2024 · 2 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Contributor

barneygale commented Nov 21, 2024

Bug report

Bug description:

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:

>>> from urllib.request import urlopen
>>> 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.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@barneygale barneygale added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 21, 2024
@barneygale barneygale changed the title urllib.request.urlopen('file:...').url incorrect urllib.request.urlopen('file:...').url incorrect value Nov 21, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Nov 21, 2024
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.
@kanishka-coder0809
Copy link

Hi @barneygale I can work upon this issue ...Can you provide some more details about the issue.

@barneygale
Copy link
Contributor Author

I'm sorry @kanishka-coder0809, I'm afraid I already opened a PR for this issue shortly before your comment: #127091

barneygale added a commit to barneygale/cpython that referenced this issue Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants