wb_download.py: use HTTPS, add a timeout and raise_for_status()
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Mở lectures/_static/lecture_specific/pandas/wb_download.py và kiểm tra fetch ở các dòng 6-9. Cập nhật request như đã mô tả, sau đó kiểm tra thủ công rằng endpoint HTTPS của World Bank trả về workbook như mong đợi, vì static asset này không được CI thực thi. Được xem là hoàn tất khi các lỗi được hiển thị rõ ràng và workbook vẫn hỗ trợ việc đọc ở downstream.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 75
- Fork
- 36
- Merge trung bình
- 37 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của QuantEcon/lecture-python-programming
-
pandas: mean imputation corrupts Argentina's GDP per capita in the later plotCó thể làm lại được @omiiikb07 đã nhận 11 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
QuantEcon/lecture-python-programming#658 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 95/100
Tất cả issue của QuantEcon/lecture-python-programming
Issue tương tự
-
bug frontend good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
oscarbol09/thesisforge#61 ·
-
bug status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
mastra-ai/mastra#31093 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
osmlab/name-suggestion-index#13165 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ReduxISU/Redux_Frontend#327 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Remove hardcoded personal Auth0 tenant and live AUDIENCE from committed .env.development templateĐang mởenhancement ready-for-agent
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100