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
The request is still using {'Content-Type': 'application/json'}
Error message from our API: '{"code":"API_MALFORMED_BODY","message":"Malformed JSON"}'
Shouldn't the POST change the headers if using multipart forms?
Specifying the following also does not work because the boundaries are not included in the headers: resp = client.post('URL', files=data, headers={'Content-Type': 'multipart/form-data'})
The text was updated successfully, but these errors were encountered:
Okay, it's a little bit ambiguous what behavior you'd expect in those cases.
But, yes, I can see why you might like the client-default Content-Type to be overridden there.
I don't think this is related to #2382, it looks like the same behaviour that we've had for a while...
importhttpx# Client with Content-Type headers set.client=httpx.Client(headers={"Content-Type": "application/json"})
# An `application/x-www-form-urlencoded` POST request.# Essentially the same case as your multipart example, but just a little more simple.request=client.build_request("POST", "https://www.example.com", data={"a": "b"})
print(request.headers)
print(request.content)
All the cases have Content-Type: application/json set, but have a form-encoded body.
The quickest solution to the issue would be to stop doing this...
# Not needed. You'll get this header if you use `json=...` anyways.# Specifying a `Content-Type` header on the client instance is almost always going to# be a bad idea. Eg. you'll also get odd looking GET requests which have a `Content-Type`# header but no content.client=httpx.Client(headers={"Content-Type": "application/json"})
But, yeah, there's other options too. I can see that we might be able to change the priority rules so that client headers only get applied if they're not overriding the auto-generated request headers.
Or... we could guard against setting certain headers on the client. In particular we could prevent setting the Content-Type, Content-Length, Host and Transfer-Encoding headers, which are all auto-populated based on the request.
After testing #2382 it seems that the request headers are not being updated correctly.
The request has the following header
{'Content-Type': 'multipart/form-data; boundary=b194f2c9bc744ebf40c3fa03d6d53987'}
However if using an initialized client:
The request is still using
{'Content-Type': 'application/json'}
Error message from our API:
'{"code":"API_MALFORMED_BODY","message":"Malformed JSON"}'
Shouldn't the POST change the headers if using multipart forms?
Specifying the following also does not work because the boundaries are not included in the headers:
resp = client.post('URL', files=data, headers={'Content-Type': 'multipart/form-data'})
The text was updated successfully, but these errors were encountered: