SRE scripts often interact with APIs. Know how to make requests and handle responses.
Using requests library:
import requests
response = requests.get('https://api.example.com/status')
if response.status_code == 200:
data = response.json()
else:
handle_error(response)
Key concepts:
- Handle HTTP errors (status codes, timeouts)
- Parse JSON responses
- Add headers (authentication, content-type)
- Retry on transient failures
Interview tip: Think about error handling. What if the API is down? What if it returns unexpected data? Production code must handle these cases.