I'm trying to send post data to an api which needs to be in json. If the requests header doesn't have Content-type: application-json
the request fails and I get an HTTPError: 415 Client Error: Unsupported Media Type for url
However requests only seems to add in this header if I use the inbuilt json parser. Even though the docs seem to suggest the below is equivalent:
>>> r = requests.post(url, data=json.dumps(payload))
>>> r = requests.post(url, json=payload)
Which means that I need to use the built in json parser (or manually add the Content-type header).
However my post data has several Decimal fields (from api converted via json.loads(response.text, parse_float=decimal.Decimal)
to be saved in a django DecimalField) which when using the inbuilt requests parser gives the error:
TypeError: Decimal('1560.35') is not JSON serialisable
Is there a way I can use a different json parser with requests (e.g. simplejson which deals with decimals) and have the content-type still specified.