You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lectures that call the World Bank API fail their build when the API is slow or down #877
Three lectures fetch data from api.worldbank.org through wbgapi while they build: lectures/business_cycle.md (import wbgapi as wb at line 41, then wb.series.info and wb.data.DataFrame for NY.GDP.MKTP.KD.ZG, SL.UEM.TOTL.NE.ZS and FS.AST.PRVT.GD.ZS), lectures/heavy_tails.md (line 34, then wb.data.DataFrame and wb.economy.info near line 803) and lectures/inequality.md (line 94, then SI.POV.GINI at lines 553 and 572 and NY.GDP.PCAP.KD at line 723).
The calls set no timeout and no retry. A 502 from the API fails the cell, and a request that hangs runs to the 600 s cell timeout, so the build fails either way. Both have happened in QuantEcon/actions' lecture matrix: on 2026-11-16 (run 43789867796, see QuantEcon/actions#333) all three lectures failed on APIError: [502] Bad Gateway from api.worldbank.org, and on 2026-11-17 (run 44030094100) the SI.POV.GINI cell in inequality.md timed out after 600 s. A run on 2026-11-12 (43135770816) also failed in business_cycle.md and timed out in inequality.md, but its tracebacks are no longer available.
A possible change: a hidden setup cell after each import wbgapi as wb that sets a request timeout (wbgapi 1.0.14 passes wb.get_options to requests.get, so wb.get_options['timeout'] = 60 works) and retries a failed request up to three times. A timeout alone would turn slow successes into failures, so the retry matters. wbgapi has no public retry option: a retry means wrapping its private _queryAPI, or a change in wbgapi itself. Any such change touches lecture content, so it needs a person's review before it merges.
Not every one of these three lectures needs the live API: only one of them is about fetching data from it.
heavy_tails.md: the calls sit in a hidden-input helper (extract_wb) that only fetches GDP data for plots. The lecture isn't about the API, so it's a candidate for moving to a snapshot in QuantEcon/data-lectures.
inequality.md: it shows once how to look up a series ID with wbgapi and then fetches the Gini and GDP-per-capita data. It keeps the live fetch for now.
business_cycle.md: its "Data acquisition" section teaches wb.series.info and pulls data up to today, so it keeps the live fetch for now. data-lectures already holds snapshots of its three series (gdp_growth_annual.csv, unemployment_rate_annual.csv, private_credit_to_gdp.csv), which nothing reads yet, if that's ever wanted.
This stays open while the approach for the live-fetch lectures is decided: for example, re-running a lecture when a build fails on a network error, rather than changing lecture code for intermittent outages.
Activity
mmcky commentedon Nov 22, 2026
Not every one of these three lectures needs the live API: only one of them is about fetching data from it.
heavy_tails.md: the calls sit in a hidden-input helper (extract_wb) that only fetches GDP data for plots. The lecture isn't about the API, so it's a candidate for moving to a snapshot in QuantEcon/data-lectures.inequality.md: it shows once how to look up a series ID withwbgapiand then fetches the Gini and GDP-per-capita data. It keeps the live fetch for now.business_cycle.md: its "Data acquisition" section teacheswb.series.infoand pulls data up to today, so it keeps the live fetch for now. data-lectures already holds snapshots of its three series (gdp_growth_annual.csv,unemployment_rate_annual.csv,private_credit_to_gdp.csv), which nothing reads yet, if that's ever wanted.This stays open while the approach for the live-fetch lectures is decided: for example, re-running a lecture when a build fails on a network error, rather than changing lecture code for intermittent outages.