Home >>Python Requests Module >Python Requests head() Method

Python Requests head() Method

Python Requests head() Method

Python Requests head() Method in python is used to sends a request of a HEAD to the specified url, it will be done only the HTTP headers or status_code.

Syntax:
requests.head(url, args)

Parameter Values

Parameter Description
url It is Required. The request of the url
params It is Optional. A dictionary, to send as a query string. Default value is None
allow_redirects It is Optional. To redirection of a Boolean(Default value is True)
auth It is Optional. to enable a certain HTTP authentication of a tuple. Default value is None
cert It is Optional. It specifying a cert file or key of a string or a tuple. Default value is None
cookies It is Optional. To send to the specified url of a directionary of cookies. Default value is None
headers It is Optional. to send to the specified url of a dictionary of HTTP headers. Default value is None
proxies It is Optional. The proxy url of the protocol. Default value is None
stream It is Optional and indicates a Boolean. Default False
timeout It is Optional. A tuple or a number, indicating how many seconds to wait for the client to make a connection
verify It is Optional. A string or a Boolean indication to verify the servers TLS certificate or not. Default value is True
Here is an example of Python Requests head() Method:

import requests
x = requests.head('https://www.phptpoint.com/python/demopage.php')
print(x.headers)

Output:
{'Content-Encoding': 'gzip', 'Cache-Control': 'public', 'Content-Type': 'text/html', 'Date': 'Tue Mar 31 2020 14:15:56 GMT+0530 (India Standard Time)', 'Server': 'Microsoft-IIS/7.5', 'Vary': 'Accept-Encoding', 'X-Frame-Options': 'SAMEORIGIN', 'X-Powered-By': 'PHP/5-4-2. ASP.NET', 'Content-Length': '0'}