Search code examples
pythondjangopython-requestshttp-status-code-400

Python Http Client requests


I would like to retrieve product data using the POST method and pass the security key in the header. I get an HTTP 400 error:

def api(request):
   headers={'content-type':'application/json','security-key': 'valu-key'}
   url = 'http://api-content/product/GetProduct'

   x = requests.post(url, headers = headers)
   content=x.status_code
   return HttpResponse(content)

Solution

  • The HTTP 400 status code returned by API may be caused by various causes, depending on how the backend handles the incoming request. (Required header not present, incorrect post data type, incorrect query format etc.)
    Maybe you can check with GetProduct's API spec since you only pass security-key header into post method (Spec describes endpoint required header, query, body etc.)