'Python Session request is parsing the data argument wrongly

I'm trying to send a request to a server and also a json as data argument. If I use straight request, it works, but when I use session I get a bad request as result.

THIS WORKS:

import request

url = "https://whatever/api/v1/dosomething"
data = {"client":{"id":100},"job":{"name":"software developer","field_id":[1,2,3],"level":20}}
headers = {'Content-type': 'application/json'}

r = requests.get(url, data=json.dumps(data), headers=headers)

When I check r.request.body, I get the following:

'{"client": {"id": 100}, "job": {"name": "software developer", "field_id": [1, 2, 3], "level": 20}}'

THIS DOES NOT WORK:

When I try to use Session though, the request.body gets messed up.

url = "https://whatever/api/v1/dosomething"
data = {"client":{"id":100},"job":{"name":"software developer","field_id":[1,2,3],"level":20}}
headers = {'Content-type': 'application/json'}

s = requests.Session()

r = s.get(url, headers=headers, data=data, verify=False)

I get a bad request as a result of the code above, and when I check r.request.body:

client=id&job=name&job=field_id&job=level

I think I'm getting a bad request because of the request.body that got parsed in a wrong way, but I am not finding how to parse it correctly.

I already tried to use:

req = Request('GET', url, data=data, headers=headers)
prepped = req.prepare()
resp = s.send(prepped)

Can someone please help? Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source