Post Request grabs xml in postman, but when I use the python requests code generated it doesn't run

Also, the post request only works in the chrome extension and NOT in the standalone app. I get 401’s when using the standalone app. Anybody have a similar issue or know how to fix this?

have you found solution for this ? I ran into similar problem and can not find out where is the problem…it works 200 OK in Postman, 401 in the standalone Python script.

Hey @kyselak,

As this question was posted a while ago - Are you able the use the code snippet from the new code-gen UI and see if this is still a problem for you? It looks like your issues might be around Auth though, as that’s what would create that 401 response code.

You can enable this in the General section on the Settings.

I took this basic Python snippet from the code-gen:

import requests

url = "https://restful-booker.herokuapp.com/booking"

payload = "<booking>\r\n\t<firstname>Sally</firstname>\r\n\t<lastname>Brown</lastname>\r\n\t<totalprice>111</totalprice>\r\n\t<depositpaid>true</depositpaid>\r\n\t<additionalneeds>Breakfast</additionalneeds>\r\n\t<bookingdates>\r\n\t\t<checkin>2013/02/23</checkin>\r\n\t\t<checkout>2014/10/23</checkout>\r\n\t</bookingdates>\r\n</booking>"

headers ={

'Content-Type': 'text/xml',

'Accept': 'application/xml'}

response = requests.request("POST", url, headers = headers, data = payload)

print(response.text.encode('utf8')) 

It returned the basic XML response that I was expecting:

no success, I must be doing something wrong, tried support, they just keep telling me that the token has expired, but if I try call from Postman with expired token I get 401 also. And when I create fresh token it just works 200 OK, but in my app I get again 401.

Postman:

Python standalone:
REDACTED

This is the code:

import requests

url = "https://app.idoklad.cz/developer/api/v2/Contacts"

headers = {
    'Authorization': "Bearer {{accessToken}},Bearer <REDACTED>",
    'Accept': "{{accept}}",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Cache-Control': "no-cache",
    'Postman-Token': "cf2990f0-1dcf-4fb7-8575-d85dd57a898c,46932b04-efb4-4ea6-ae94-1631b76031dd",
    'Host': "app.idoklad.cz",
    'Accept-Encoding': "gzip, deflate",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

I think I can see the issue here.

If you remove the first Bearer {{accessToken}}, part from the Auth header and the Accept': "{{accept}} header it will run in Python.

1 Like

thank you very much, this solved my problem.

1 Like