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

オープン
#156,510 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
networking

調査の方向性

レポートで説明されている urllib.request.urlretrieve と urllib.request.url2pathname(parse.urlparse(...).path) の動作から始めてください。Windows でファイル名のないローカルファイルのケースを検証し、動作している明示的なファイル名とリモート URL の各バリアントを維持してください。返されるファイル名が期待される Windows パスと一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

stdlib type-bug

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
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。