To make a HTTP Head request in Python, we can use the requests
library. We'll start by installing requests
if it isn't already installed:
main.py22 chars2 lines
Once we have installed requests
, we can use the head
method to make the HTTP Head request:
main.py132 chars8 lines
In this example, we make a HTTP Head request to https://www.example.com
, and store the response object in a variable called response
. We then print the status code and headers of the response.
Note that the head
method returns a similar response object as the get
method, except that the response body is not included. This makes it a good choice for cases where we only need information about the resource, and not the content of the response.
gistlibby LogSnag