-1

I am trying to access custom headers sent back to my client by the server, but I cant find them in any of the header objects in the response object listed in the Requests documentation

1 Answer 1

1

From Requests documentation:

We can view the server’s response headers using a Python dictionary:

>>> r.headers
{
   'content-encoding': 'gzip',
   'transfer-encoding': 'chunked',
   'connection': 'close',
   'server': 'nginx/1.0.4',
   'x-runtime': '148ms',
   'etag': '"e1ca502697e5c9317743dc078f67693f"',
   'content-type': 'application/json'
}

Access specific header like this:

>>> r.headers['Content-Type']
'application/json'

>>> r.headers.get('content-type')
'application/json'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.