You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Request.post_data_json raises KeyError when content-type is missing #3093
request.post_data_json should treat the missing content-type header as "not form-urlencoded" and then use the documented JSON fallback. For the body above, it should return {"a": 1}.
This matches the upstream JavaScript implementation, which checks the header with optional access before the form-urlencoded branch.
Actual behavior
The property raises before it reaches JSON parsing:
The API docs say Request.post_data_json returns parsed form-urlencoded data and parses JSON as a fallback. A missing content-type header should not prevent that fallback path.
Then add a focused regression test for a request that has a JSON body but no content-type header, asserting that request.post_data_json returns the parsed JSON instead of raising KeyError.
Activity
rohan-patnaik commentedon Jun 8, 2026
Potential fix direction I'm thinking of raising a PR for ->
In
playwright/_impl/_network.py, read the header defensively, for example:Then add a focused regression test for a request that has a JSON body but no
content-typeheader, asserting thatrequest.post_data_jsonreturns the parsed JSON instead of raisingKeyError.