urllib: urlretrieve() seems to ignore provided host header
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- networking
調査の方向性
urllib.request.urlretrieve()、build_opener()、および opener.addheaders から調査を始め、提示された Windows/Python 3.10 の例を使って Host ヘッダーの挙動を再現します。リクエストヘッダーを requests の例と比較し、Host が意図的に特別扱いされているかを判断します。挙動が説明され、バグであることが確認された場合は回帰テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug report
I have been having issues confirming this, but urlretrieve seems to ignore the provided Host header even if it's added. It seems to correctly look at User-agent and Referer. I have two functions doing the same download, one with urlretrieve and one with requests. The requests one works as expected and fails in the same way urlretrieve fails if I remove the Host header.
def download_helper(url, fname):
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0'),
('Referer', "https://www.amd.com/en/support/graphics/amd-radeon-6000-series/amd-radeon-6700-series/amd-radeon-rx-6700-xt"),
('Host' , 'us.download.nvidia.com')]
urllib.request.install_opener(opener)
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
urllib.request.urlretrieve(url, filename=fname)
def download_helper2(url, fname):
my_referer = "https://www.amd.com/en/support/graphics/amd-radeon-6000-series/amd-radeon-6700-series/amd-radeon-rx-6700-xt"
resp = requests.get(url, verify=False, stream=True, headers={
'referer': my_referer,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0',
'Host' : 'us.download.nvidia.com'
})
total = int(resp.headers.get('content-length', 0))
with open(fname, 'wb') as file:
for data in resp.iter_content(chunk_size=1024):
size = file.write(data)
download_helper2('https://192.229.211.70/Windows/516.94/516.94-desktop-win10-win11-64bit-international-dch-whql.exe', r'516.94-desktop-win10-win11-64bit-international-dch-whql.exe')
Your environment
- CPython versions tested on: 3.10.6
- Operating system and architecture: Windows Server 2022 10.0.20348.887 ; AMD64
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·