1

I am new to python and I am trying to automate post API in which I am using post method as follows:-

headers = {'Content-Type': 'application/json',
           'Authorization': 'Basic xxxx=='}

response = requests.post(url=urlsales, data=payload,
                                headers=headers)

After running the test, getting the following output :-

print("response headers >>>>", response.headers)
response headers >>>> {'Date': 'Fri, 30 Oct 2020 14:11:34 GMT', 'Content-Type': 'application/json', 'Content-Length': '187', 'Connection': 'keep-alive', 'X-Error-Code': '500.45.001', 'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,PATCH,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Accept, Accept-Encoding, Authorization, Content-Length, Content-Type, Host, User-Agent, X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto'}


print("headers >>", headers)
{'Content-Type': 'application/json',
               'Authorization': 'Basic xxxx=='}

I am assuming there is issue with headers as when I send only 'Content-Type': 'application/json' in header , then i get 401 unauthorized which is as expected but when I add 'Authorization': 'Basic xxxx==' as mentioned above I start getting 500 internal server error

can someone please help with the possible root cause where it might have went wrong

zzz
  • 497
  • 3
  • 14
  • 32
  • HTTP 500 is related to exception in the application, means that most likely you r posting the wrong formatted payload – Reishin Oct 30 '20 at 14:41
  • Does the API support basic authentication? In this case you may use `auth=(user,pass)` parameter in post request instead of providing a header. – Tarique Oct 31 '20 at 05:05

0 Answers0