Python – Send HTTP HEAD Request
HTTP HEAD request is used to create or update a resource in a specified server.
In Python Requests library, requests.head() method is used to send a HEAD request to a server over HTTP.
Examples
1. Send HTTP HEAD Request
requests.head() returns a Response object. It contains all the data and properties like response headers, encoding, cookies, etc. Let us print out headers.
import requests
response = requests.head('https://pythonexamples.org/')
print(response.headers)
Run Code
{'Date': 'Mon, 25 Mar 2019 14:05:43 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=30', 'Server': 'Apache/2', 'X-Powered-By': 'PHP/5.6.30', 'Link': '<https://pythonexamples.org/wp-json/>; rel="https://api.w.org/", <https://pythonexamples.org/>; rel=shortlink', 'Vary': 'Accept-Encoding', 'Referrer-Policy': 'no-referrer-when-downgrade'}
About HTTP HEAD Request
HEAD request is similar to GET, with the difference being that response to HEAD request do not contain response body. HEAD request is used to know the meta of a response to GET request.
Summary
In this Python Tutorial, we learned about HTTP HEAD Request in requests module.
Next Topic ⫸
Python Requests - DELETE
⫷ Previous Topic
Python Requests - PUT