shaare.it

JSON Body Wrong Type

7 Dec 2025

1 min read

JSON body wrong type

$ python -c "import requests; requests.post('https://api.example.com', json='{"x":1}')"
# Sent as a JSON string; server may double-parse or error

Why this happens

json= expects Python objects (dict/list). Passing a pre-encoded string results in wrong double-encoding.

Fix

Use json= with dicts; use data= for form bodies.

Wrong code

import requests
requests.post('https://api.example.com', json='{"x":1}')

Fixed code

import requests
requests.post('https://api.example.com', json={'x':1}, timeout=10)