You can use either requests or urllib module to get the HTTP response code from a URL.
Here is an example that shows how to use these modules:
Using requests
import requestsurl = "https://qa.tellustheanswer.com/"try: req = requests.head(url) print(req.status_code)except requests.ConnectionError as e: print(e)
Using urllib
from urllib.error import URLErrorimport urllib.requesturl = "https://qa.tellustheanswer.com/"try: conn = urllib.request.urlopen(url) print(conn.getcode())except urllib.error.URLError as e: print(e)