kumistatus/httptools/__init__.py

13 lines
388 B
Python
Raw Normal View History

2016-09-13 21:27:10 +00:00
import urllib.request, urllib.error
def getStatus(url):
if not "://" in url:
url = "http://" + url
req = urllib.request.Request(url, data=None, headers={'User-Agent': 'KumiStatus/0.8.15 (+https://kumig.it/kumitterer/kumistatus)'})
2016-09-13 21:27:10 +00:00
try:
return urllib.request.urlopen(req).getcode()
2016-09-13 21:27:10 +00:00
except urllib.error.HTTPError as e:
return e.code
except urllib.error.URLError:
return False