You are looking for the Response.reason attribute:

Copy>>> import requests
>>> r = requests.get('http://httpbin.org/get')
>>> r.status_code
200
>>> r.reason
'OK'
>>> r = requests.get('http://httpbin.org/status/500')
>>> r.reason
'INTERNAL SERVER ERROR'
Answer from Martijn Pieters on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › response-headers-python-requests
response.headers - Python requests - GeeksforGeeks
July 12, 2025 - The response.headers object in Python's requests library functions as a special dictionary that contains extra information provided by the server when we make an HTTP request. It stores metadata like content type, server details and other headers, ...
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.34.0 documentation
Response.raw is a raw stream of bytes – it does not transform the response content. If you really need access to the bytes as they were returned, use Response.raw. If you’d like to add HTTP headers to a request, simply pass in a dict to the headers parameter.
Discussions

Get HTTP response header using Python requests module - Stack Overflow
I am using 'requests' module in Python to query a RESTful API endpoint. Sometimes, the endpoint returns an HTTP Error 500. I realize I can get the status code using requests.status_code but when ... More on stackoverflow.com
🌐 stackoverflow.com
How to print out http-response header in Python - Stack Overflow
Update: Based on comment of OP, that only the response headers are needed. Even more easy as written in below documentation of Requests module: We can view the server's response headers using a Python dictionary: More on stackoverflow.com
🌐 stackoverflow.com
Using headers with the Python 'Requests' library's get() method - Stack Overflow
I recently stumbled upon this great library for handling HTTP requests in Python; found on Requests: HTTP for Humans. I love working with it, but how can I add headers to my get requests? More on stackoverflow.com
🌐 stackoverflow.com
How to fetch response headers using Python Requests Library?
UPDATE: the issue was that I wasn't passing correct cookies with the requests More on reddit.com
🌐 r/learnpython
6
1
September 27, 2022
People also ask

How do I rotate headers to avoid detection?

Maintain a list of realistic header sets and randomly select one per request. Vary the User-Agent, Accept-Language, and Referer values. Combine this with proxy rotation for better results.

🌐
scrapfly.io
scrapfly.io › blog › posts › python-requests-headers-guide
Guide to Python Requests Headers - Scrapfly Blog
When should I use browser automation instead of requests?

Use browser automation tools like Playwright or Selenium when you need to load JavaScript, handle clicks, or when you're blocked by TLS fingerprinting. While these tools solve the TLS problem, they are slower and use more computer resources. ScrapFly offers both simple requests and full browser automation.

🌐
scrapfly.io
scrapfly.io › blog › posts › python-requests-headers-guide
Guide to Python Requests Headers - Scrapfly Blog
Why do my headers work in testing but fail in production?

This is usually because you're sending too many requests. In testing, your low number of requests doesn't trigger extra anti-bot checks. In production, more requests trigger TLS fingerprinting. Even with perfect headers, a different TLS fingerprint will get you blocked. ScrapFly solves this by using real browser TLS profiles.

🌐
scrapfly.io
scrapfly.io › blog › posts › python-requests-headers-guide
Guide to Python Requests Headers - Scrapfly Blog
🌐
Scrapfly
scrapfly.io › blog › posts › python-requests-headers-guide
Guide to Python Requests Headers - Scrapfly Blog
April 10, 2026 - Headers can be easily managed using Python's requests library. This lets you get headers from a response or set custom headers to customize each request.
🌐
W3Schools
w3schools.com › python › ref_requests_response.asp
Python requests.Response Object
Python Examples Python Compiler ... Q&A Python Bootcamp Python Training ... The requests.Response() Object contains the server's response to the HTTP request....
Top answer
1 of 8
28

Update: Based on comment of OP, that only the response headers are needed. Even more easy as written in below documentation of Requests module:

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'
}

And especially the documentation notes:

The dictionary is special, though: it's made just for HTTP headers. According to RFC 7230, HTTP Header names are case-insensitive.

So, we can access the headers using any capitalization we want:

and goes on to explain even more cleverness concerning RFC compliance.

The Requests documentation states:

Using Response.iter_content will handle a lot of what you would otherwise have to handle when using Response.raw directly. When streaming a download, the above is the preferred and recommended way to retrieve the content.

It offers as example:

>>> r = requests.get('https://api.github.com/events', stream=True)
>>> r.raw
<requests.packages.urllib3.response.HTTPResponse object at 0x101194810>
>>> r.raw.read(10)
'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'

But also offers advice on how to do it in practice by redirecting to a file etc. and using a different method:

Using Response.iter_content will handle a lot of what you would otherwise have to handle when using Response.raw directly

2 of 8
14

Here's how you get just the response headers using the requests library like you mentioned (implementation in Python3):

import requests

url = "https://www.google.com"
response = requests.head(url)
print(response.headers) # prints the entire header as a dictionary
print(response.headers["Content-Length"]) # prints a specific section of the dictionary

It's important to use .head() instead of .get() otherwise you will retrieve the whole file/page like the rest of the answers mentioned.

If you wish to retrieve a URL that requires authentication you can replace the above response with this:

response = requests.head(url, auth=requests.auth.HTTPBasicAuth(username, password))
Find elsewhere
🌐
CodeSignal
codesignal.com › learn › courses › basic-python-and-web-requests › lessons › exploring-http-response-headers-with-pythons-requests-library
Exploring HTTP Response Headers with Python's requests ...
Let's use Python's requests library to see some of these headers in action, using the solution code as an example. First, we make an HTTP GET request to our target URL, which gives us a Response object.
🌐
ReqBin
reqbin.com › code › python › jyhvwlgz › python-requests-headers-example
How to send HTTP headers using Python Requests Library?
You can pass HTTP headers to Python Requests Library methods using the headers = parameter. Headers are passed as a dictionary of header name: header value pairs. The Requests Library does not change its behavior depending on the passed headers ...
🌐
Python.org
discuss.python.org › python help
HTTP response headers - Python Help - Discussions on Python.org
July 13, 2022 - I need to use http.client and access the response headers. Code like this seems to work: import http.client response: http.client.HTTPResponse = ... for name in response.headers: value = response.headers[name] …
🌐
datagy
datagy.io › home › python requests › using headers with python requests
Using Headers with Python requests • datagy
December 30, 2022 - HTTP headers allow the client and server to pass additional information while sending an HTTP request or receiving a subsequent response. These headers are case-insensitive, meaning that the header of 'User-Agent' could also be written as ...
🌐
GitHub
gist.github.com › a9612b2efb4f2e090814
Python - iterating over HTTP response headers using Requests · GitHub
Python - iterating over HTTP response headers using Requests - http-response-headers-requests.py
🌐
Real Python
realpython.com › python-requests
Python's Requests Library (Guide) – Real Python
July 23, 2025 - You make a GET request in Python using requests.get() with the desired URL. To add headers to requests, pass a dictionary of headers to the headers parameter in your request. To send POST data, use the data parameter for form-encoded data or ...
🌐
LabEx
labex.io › tutorials › python-how-to-set-custom-headers-in-a-python-requests-call-398067
How to set custom headers in a Python requests call | LabEx
The response from httpbin.org/headers shows us exactly what headers were received, confirming our custom headers were sent successfully · Let's create another example where we pretend to be a mobile device. This can be useful when testing mobile-responsive websites: ... import requests url = 'https://httpbin.org/headers' ## Header to simulate an iPhone mobile_headers = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' } print("Making request with mobile device headers...") response = requests.get(url, headers=mobile_headers) ## Print the response content print(response.json())
🌐
Edureka
edureka.co › blog › python-requests-tutorial
Python Requests Tutorial | Using Requests Library in Python | Edureka
November 27, 2024 - This means that req.headers[‘Content-Length’], req.headers[‘content-length’] and req.headers[‘CONTENT-LENGTH’] will all return the value of the just the ‘Content-Length’ response header. We can also check if the response obtained is a well-formed HTTP redirect (or not) that could have been processed automatically using the req.is_redirect property. This will return True or False based on the response obtained. You can also get the time elapsed between sending the request and getting back a response using another property.
🌐
Apidog
apidog.com › blog › python-requests-headers
How to make Requests Headers with Python
February 4, 2026 - Before we delve into headers, let's make sure we're all on the same page with Python requests. If you haven't installed the requests library yet, you can do so using pip: ... The requests library simplifies making HTTP requests. It’s perfect for interacting with web services and APIs. Here’s a basic example of making a GET request: import requests response = requests.get('https://api.example.com/data') print(response.status_code) print(response.json())
🌐
WebScraping.AI
webscraping.ai › faq › requests › can-i-access-the-response-headers-using-requests
Can I access the response headers using Requests? | WebScraping.AI
import requests # Make a GET request to a URL response = requests.get('https://httpbin.org/get') # Access the response headers headers = response.headers # Print the header keys and values for key, value in headers.items(): print(f'{key}: {value}') # You can also access specific headers directly content_type = headers['Content-Type'] print(f'Content-Type: {content_type}')
🌐
Real Python
realpython.com › lessons › responses-content-and-headers
Responses: Content and Headers (Video) – Real Python
The headers attributes returns a Python dictionary with all of the response headers. 00:00 Next, let’s talk about the data that actually got sent back from the server that’s in the body of the response. I’m going to go ahead and close my script and expand my terminal back up here and clear it. 00:16 So, I’m going to step back into bpython, my REPL. You can use just whatever REPL you have. This is nice because it just shows a lot of extra information. Okay. 00:25 We’re going to import requests again, we’ll set up our url,
Published   March 6, 2019