urllib: urlretrieve() on Windows, given a local file url and no target filename method returns an invalid filename
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
On windows, if the request.urlretrieve method receives an url pointing to a local file and no filename is provided, then the returned filename will be invalid:
from urllib import request
request.urlretrieve("file:///C:/testdir/testfile.txt")
# ('\\\\\\C:\\testdir\\testfile.txt', <...>)
# Expected 'C:\\testdir\\testfile.txt'
# Other variants of urlretrieve calls work as expected
request.urlretrieve("file:///C:/testdir/testfile.txt", "C:\\testdir\\testcopy.txt")
# ('C:\\testdir\\testcopy.txt', <...>)
request.urlretrieve("https://google.com/")
# ('C:\\Users\\...\\Temp\\tmpwp4pu1bw', <...>)
I would expect that if no copy is necessary then the filename returned by request.urlretrieve would be equal to request.url2pathname(parse.urlparse("file:///C:/testdir/testfile.txt").path)
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
- gh-156550
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with urllib.request.urlretrieve and the urllib.request.url2pathname(parse.urlparse(...).path) behavior described in the report. Verify the no-filename local-file case on Windows while preserving the working explicit-filename and remote-URL variants; done means the returned filename matches the expected Windows path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100