Interview Prep/Python for DevOps/Data formats, HTTP & REST APIs

How do you make an HTTP request with `requests` the right way?

BeginnerConceptData formats, HTTP & REST APIs
Answer
import requests
resp = requests.get("https://api.github.com/repos/acme/app/releases/latest",
                    headers={"Authorization": f"Bearer {token}",
                             "Accept": "application/vnd.github+json"},
                    timeout=(3.05, 15))
resp.raise_for_status()
tag = resp.json()["tag_name"]

Three non-negotiables: a timeout (the default is to wait forever), raise_for_status() (requests does not raise on 4xx/5xx), and credentials from the environment or a secrets manager, never hardcoded.

All Python for DevOps questions Roadmap: Python for automation

More on Data formats, HTTP & REST APIs