Question

I'm having issues sending a put using the requests module. I have been able to do a get successfully and using a Advanced Rest Client for Chrome I have verified my payload is correct. However, I get a generic error saying I send a bad request. I am new to web service calls and I'm not sure if what I am doing is completely wrong but this is what I am attempting:

import requests
payload = {'payload': '<request>some request xml</request>'}
headers = {'content-type': 'application/xml'}

r = requests.put('https://the.url', data=payload, auth=HTTPBasicAuth('user', 'password'), headers=headers)

I know 100% the XML, URL, and Credentials are correct, so why doesn't the above work? The only thing that I can think of is that the key for the payload needs to be something specific but I'm not sure if that is correct or how to figure out what it should be...

The response is a 'HTTP Status 400 - Bad Request'

Was it helpful?

Solution

After digging more into the Quick Start Guide I found this tid-bit of information:

There are many times that you want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.

I did try this originally but apparently I had a typo because the error I got indicated I needed to pass in a dict.

Regardless, passing in the straight XML instead of a dictionary has fixed the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top