Fetching data from the web

17-minute lesson · module-files-04

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Fetching data from the web

17-minute lesson · module-files-04

  • Fetch the contents of a URL with the standard-library urllib.request.
  • Decode downloaded bytes into a string you can work with.
  • Use the third-party requests library for a friendlier API.
  • Explain why network access works locally but not in the browser sandbox.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Files / Fetching Something From The Web

Adaptation notes. Read-along lesson. Outbound network requests from the in-browser Pyodide sandbox are blocked by the browser security model, so there is no graded coding step; the code is for reading and for running on the student's own machine. Examples are ours; prose is original.

License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced. requests is Apache-2.0 licensed; only API names are referenced.