Automation · Python Automation
requests
Cheat sheet · https://pcornel.dk/topic.php?topic=5266
Answer
requests is the popular Python HTTP library for calling REST APIs: requests.get or post with headers, json= payloads, auth, timeout and raise_for_status() for error handling.
Remember
- Always set a timeout.
- Call raise_for_status() to catch HTTP errors.
- Use a Session to reuse connections.
First checks
python3 -c "import requests;r=requests.get('https://example.com',timeout=10);print(r.status_code)"— request with timeout- raise_for_status() — error handling
- Session with retries (HTTPAdapter) — resilience
Commands
requests- Python HTTP library for calling REST APIs.
Verify in this order
request → API → response → status check
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5266