Skip to content

gh-156510: Fix urlretrieve() file URL path on Windows - #156550

Open
vinitsonawane45 wants to merge 3 commits into
python:mainfrom
vinitsonawane45:gh-156510-urlretrieve-file-url
Open

gh-156510: Fix urlretrieve() file URL path on Windows#156550
vinitsonawane45 wants to merge 3 commits into
python:mainfrom
vinitsonawane45:gh-156510-urlretrieve-file-url

Conversation

@vinitsonawane45

Copy link
Copy Markdown

Bug

urllib.request.urlretrieve() can return an invalid local path when given a file:// URL without an explicit filename argument on Windows.

Root cause

The no-filename fast path normalized a URL-formatted path using os.path.normpath(). On Windows, this can produce an invalid filesystem path.

Fix

Use url2pathname(url, require_scheme=True, resolve_host=True) on the complete file:// URL so it is correctly converted to a local filesystem path.

Tests

Added a regression test for urlretrieve() with a file:// URL and no explicit filename.

Fixes gh-156510.

@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

urllib: urlretrieve() on Windows, given a local file url and no target filename method returns an invalid filename

1 participant