wb_download.py: use HTTPS, add a timeout and raise_for_status()
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 88/100
Rechercherichtung
Öffne lectures/_static/lecture_specific/pandas/wb_download.py und überprüfe den Abruf in den Zeilen 6-9. Aktualisiere die Anfrage wie beschrieben und prüfe anschließend manuell, dass der HTTPS-World-Bank-Endpunkt die erwartete Arbeitsmappe zurückgibt, da dieses statische Asset nicht von CI ausgeführt wird. Erledigt ist die Aufgabe, wenn Fehler klar sichtbar werden und die Arbeitsmappe weiterhin das nachgelagerte Einlesen unterstützt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 72
- Forks
- 31
- Ø Merge
- 2 T. 20 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus QuantEcon/lecture-python-programming
-
environment.yml uses conda channel 'default' instead of 'defaults'; trailing space in _toc.yml Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
QuantEcon/lecture-python-programming#607 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
QuantEcon/lecture-python-programming#622 · 4 Kommentare ·
-
broken-links bug documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 48/100
QuantEcon/lecture-python-programming#597 · 1 Kommentar ·
Alle Issues in QuantEcon/lecture-python-programming
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Automattic/studio#4908 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
sugarlabs/musicblocks#8847 ·