I have been using the below to checking if a website is valid or not -
from urllib.request import Request, urlopen from urllib.error import URLError, HTTPErro