

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Data Formats
incomplete
2: Parsing JSON
incomplete
3: Variable-Depth JSON
incomplete
4: Fetching JSON
incomplete
5: CSV Files
incomplete
6: CSV Type Conversion
incomplete
7: Filtering CSV Rows
incomplete
8: Writing CSV Files
incomplete
9: Appending to CSV Files
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
So far, our JSON has been sitting there waiting for us. But in many cases, you'll need to go fetch it from an API first. If an API serves you JSON over HTTP, that means you'll:
Python's built-in urllib.request module can make simple HTTP requests.
import urllib.request
url = "https://api.example.com/stocks"
with urllib.request.urlopen(url) as response:
raw_data = response.read()
data = json.loads(raw_data)
urlopen() sends the requestread() gets the response bodyjson.loads() parses the JSONComplete the fetch_device_status function. It accepts a device_id string and fetches its status (a dictionary) from the SnackStack API.
f"https://api.snackstack.dev/devices/{device_id}/status"