Skip to content

Instantly share code, notes, and snippets.

@seenimohamed
Created May 25, 2018 10:48
Show Gist options
  • Save seenimohamed/0e41bc442e9ffb8aa2abf7337239311d to your computer and use it in GitHub Desktop.
Save seenimohamed/0e41bc442e9ffb8aa2abf7337239311d to your computer and use it in GitHub Desktop.
To check whether a given url is up or not
from six.moves import urllib
import requests
def url_is_alive(url):
"""
Checks that a given URL is reachable.
:param url: A URL
:rtype: bool
"""
request = urllib.request.Request(url)
request.get_method = lambda: 'HEAD'
# print(request.head(url).status_code)
try:
urllib.request.urlopen(request,timeout=1)
return True
except :
return False
if __name__ == '__main__':
status = url_is_alive(url)
print(status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment