wb_download.py: use HTTPS, add a timeout and raise_for_status()
まだ誰も着手していません。
評価
調査の方向性
lectures/_static/lecture_specific/pandas/wb_download.py を開き、6-9行目の fetch を確認します。説明されているとおりにリクエストを更新し、この静的アセットは CI で実行されないため、HTTPS の World Bank エンドポイントが期待どおりのワークブックを返すことを手動で確認します。エラーが明確に表面化し、ワークブックが引き続き下流の読み込みをサポートできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
lectures/_static/lecture_specific/pandas/wb_download.py fetches the World Bank indicator over plain HTTP and writes the response body to disk without checking whether the request succeeded. Raised by Copilot while reviewing the downstream port at QuantEcon/lecture-python-programming.ml#6; it is upstream code, so it belongs here rather than in a translation edition.
Current lines 6-9:
wb_data_query = "http://api.worldbank.org/v2/en/indicator/gc.dod.totl.gd.zs?downloadformat=excel"
r = requests.get(wb_data_query)
with open('gd.xls', 'wb') as output:
output.write(r.content)
Three points, in rough order of how much they matter:
No error check. On any non-200 response the error page body is written to gd.xls, and the failure only surfaces further down as an opaque pd.read_excel parse error rather than as the network problem it actually is. r.raise_for_status() turns that into a clear failure at the point of the fault.
Plain HTTP. api.worldbank.org serves HTTPS, so this is a free upgrade — and it is a file the lectures hold up as example code, which is the argument for getting it right beyond the MITM exposure itself.
No timeout. requests.get without timeout blocks indefinitely if the endpoint stops responding, which is an unpleasant failure mode inside a notebook build.
Suggested:
wb_data_query = "https://api.worldbank.org/v2/en/indicator/gc.dod.totl.gd.zs?downloadformat=excel"
r = requests.get(wb_data_query, timeout=30)
r.raise_for_status()
with open('gd.xls', 'wb') as output:
output.write(r.content)
Note this script is a static asset rather than an executed cell, so nothing in CI exercises it — worth a manual check that the HTTPS endpoint returns the same workbook before merging.
- 主要言語
- JavaScript
- スター
- 72
- フォーク
- 31
- 平均マージ
- 2日 20時間
- マージ済み PR(30日)
- 8
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
QuantEcon/lecture-python-programming のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
QuantEcon/lecture-python-programming#607 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
QuantEcon/lecture-python-programming#622 · コメント 4 件 ·
-
broken-links bug documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
QuantEcon/lecture-python-programming#597 · コメント 1 件 ·
QuantEcon/lecture-python-programming の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Automattic/studio#4908 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
sugarlabs/musicblocks#8847 ·