'requests <Response [500]>
I am looking to use the requests class to get data from the web and then post changes to the namespace XML and load back up.
I am able to log-in and get data using requests via:
data_req = requests.get(proj_data_url, headers=headers, auth=(_user, _pw))
where headers is {'X-ApiKey': A-ApiKey, 'Authorization': Authorization}
data_req is a <Response [200]>
I then use
data_tree = xml.etree.ElementTree.fromstring(data_req.content)
to convert into the and successfully make changes to the data_tree
I then use
data_set = xml.etree.ElementTree.tostring(data_tree)
to convert back to a string.
I then attempt to post the changes back up via:
_response = requests.post(proj_data_url, data=data_set, headers=headers, auth=(_user, _pw))
but receive _response = <Response [500]>, which is apparently a server error.
Can anyone help?
Solution 1:[1]
So without knowing the Server or the XML you're posting, there's no way anyone can help with a server error.
The 500 means that the application that you're speaking to, did not handle something being wrong internally. For example, if the application is written in Python then the 500 could be the result of an unhandled exception in the code.
Without more details, you should instead endeavor to contact the site administrators for help. They can inspect their logs, fix their application, and tell you how to properly send a request to their service.
One thing you might try doing, is setting the content-type for your POST request. You can do this by updating headers like so
headers['Content-Type'] = 'text/xml' # or 'application/xml'
(See this answer to determine which you should send.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
