HTTP GET Request with requests
Make a GET request and handle the response.
Code
Python
import requests
response = requests.get("https://api.example.com/users")
response.raise_for_status()
data = response.json()
print(data)
# Or raw text
text = response.textLine-by-line explanation
- 1.Import the requests library (pip install requests).
- 2.Call requests.get() with the URL.
- 3.raise_for_status() raises an error for 4xx/5xx.
- 4.response.json() parses JSON; response.text for raw text.
Expected output
{"users": [...]}