Feb-15-2021, 01:51 PM
Feb-15-2021, 02:29 PM
The example is based only on the standard library of Python.
The 3rd party requests module send some User-Agent string, which works in the most cases.
from urllib.request import Request, urlopen from urllib.error import HTTPError, URLError # You can catch HTTPError and URLError def get_header(url): header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:77.0) Gecko/20100101 Firefox/77.0"} request = Request(url, headers=header, method="HEAD") response = urlopen(request) if response.status == 200: return dict(response.headers) get_header("https://python-forum.io/Thread-Get-HTTP-Header")PS: User-Agent is often needed in Headers, because many web applications are checking if it's a real browser and not a bot.
The 3rd party requests module send some User-Agent string, which works in the most cases.
Feb-15-2021, 05:53 PM
Thanks for the demonstration, I managed to do it as follows:
# Function -> Main function that receives request web : def application(self, environ, start_response): # Function -> Get the type of content : v_cot = environ['CONTENT_TYPE']Thanks.