Recoba20 Recoba20 - 5 months ago 61
HTTP Question

Put request working in curl, but not in Python

I am trying to make a 'put' method with curl everything is working fine and I got the JSON back:

curl -X PUT -d '[{"foo":"more_foo"}]' http://ip:6001/whatever?api_key=whatever


But for some reason when using the python
requests
module as follow:

import requests
url = 'http://ip:6001/whatever?api_key=whatever'

a = requests.put(url, data={"foo":"more_foo"})

print(a.text)
print(a.status_code)


I get the following error:


500 Internal Server Error

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.


NB: The server is up and running.

Answer Source

The data should be dumped:

a = requests.put(url, data=json.dumps([{"foo":"more_foo"}]))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download