

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Communicating on the Web
incomplete
2: HTTP Requests and Responses
incomplete
3: HTTP Powers Websites
incomplete
4: HTTP URLs
incomplete
5: Using URLs in HTTP
incomplete
6: Requests and Responses Quiz
incomplete
7: Pyfetch
incomplete
8: Web Clients
incomplete
9: Web Servers
incomplete
This lesson's interactive features are locked, please to keep using them
In this course, we'll be using the pyfetch function from the pyodide.http module to make HTTP requests. We already used it in the last two assignments!
The pyfetch function is designed to work in WebAssembly environments and follows an API pattern similar to the browser's fetch API but adapted for Python.
response = await pyfetch(url, method="GET", headers=headers)
response_data = await response.json()
We'll go in-depth on the various things happening in this standard pyfetch call later, but let's cover some basics for now.
response is the data that comes back from the serverurl is the URL we are making a request tomethod specifies the HTTP method to use (GET, POST, etc.)headers is a dictionary containing HTTP headers to send with the requestawait response.json() converts the JSON response data from the server into a Python objectFix the bug in the code.
The problem is that we aren't waiting for the response to come back before continuing with our code. We're calling .json on a coroutine instead of the actual response.
More on .json() and coroutines later.