Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

requests

Direct 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.

When to use this

Use this when making HTTP calls with requests.

First 30 seconds

1. requests for HTTP APIs.

2. Always set timeouts.

3. raise_for_status.

4. Sessions with retries/backoff.

5. Verify TLS (never verify=False in production).

Operational verification

request → API → response → status check

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Python automation runtime
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPython automation runtime · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior. · Python
Key commandrequests
Scope / prerequisiteUse this when making HTTP calls with requests.
Reference · 1
What next?3 suggested next steps
Catalog command links1
Evidence0
On this pageJump to a specific section
Automation command reference

Primary Commands

Configuration and operational commands for this Topic.

Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Common mistakes Narrow the fault
  • No timeout= (waits forever).
  • verify=False to get past certificate errors.
  • Ignoring pagination (next).
Key points
  • Always set a timeout.
  • Call raise_for_status() to catch HTTP errors.
  • Use a Session to reuse connections.
Key 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
ReferenceWhy it matters1 section · depth on demand

What it is

requests is the standard Python HTTP client for REST APIs: methods, headers, auth, JSON bodies and TLS verification.

ReferenceImportant terms & boundaries2 sections · depth on demand

How it works

A Session reuses TCP/TLS connections and default headers across calls, which is faster and keeps auth in one place. raise_for_status() turns 4xx/5xx into exceptions, r.json() parses the body, and verify= points to a CA bundle when the API uses an internal CA. Paginated APIs return a next URL to follow until it is null.

Example

import requests
s = requests.Session()
s.headers["Authorization"] = f"Token {token}"
r = s.get(f"{nb}/api/dcim/devices/", params={"site": "oslo"}, timeout=10)
r.raise_for_status()
devices = r.json()["results"]
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPython automation runtime current

Authoritative/upstream documentation reviewed for bounded claims in Python Automation > requests. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.python.org/3/ · confidence 94%
Confirmation

Confirm action

Continue?