Hands-on Lab·Python Automation for IT
Python JSON API Requests and Responses
Sending data is where the errors get interesting: `data=` and `json=` do completely different things to the same dict, a rejected request has an explanation you have to go and fetch, and `json=` refuses five types that appear in real payloads - datetimes, Decimals, UUIDs, Paths and sets. This guide fixes each, and explains why money goes on the wire as a string.
APIs and Cloud Guide 26 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 16 min
- Reviewed24 August 2026
Written against the versions above. `json=` has been in `requests` since 2.4.2. `json.dumps(default=...)` is standard library and unchanged. The lab's fixture echoes back whatever it receives, which makes the round trip visible.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
Before you start
-
Posting JSON
-
json= against data=
-
A 400, and reading what the server said about it
-
What json= refuses to serialise
-
So convert them, deliberately
-
Decimal, and why str rather than float
-
The whole thing as one function