python check if website is reachable

Solutions on MaxInterview for python check if website is reachable by the best coders in the world

showing results for - "python check if website is reachable"
Maximilian
08 Oct 2020
1import requests
2
3URL = "https://api.github.com"
4
5try:
6    response = requests.head(URL)
7except Exception as e:
8    print(f"NOT OK: {str(e)}")
9else:
10    if response.status_code == 200:
11        print("OK")
12    else:
13        print(f"NOT OK: HTTP response code {response.status_code}")
14
similar questions
queries leading to this page
python check if website is reachable