Commit c0281c81 authored by chrissi^'s avatar chrissi^
Browse files

Handle all Exceptions in a controlled way


Signed-off-by: chrissi^'s avatarChris Fiege <chris@tinyhost.de>
parent b009dd9e
......@@ -10,7 +10,17 @@ def http_get(url):
try:
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
except Exception as e:
print("DNS lookup for {} failed.".format(host))
return (False, e)
try:
s = socket.socket()
except Exception as e:
print("Socket setup failed")
return (False, e)
try:
s.connect(addr)
print(('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
......@@ -21,6 +31,7 @@ def http_get(url):
ret += str(data, "utf8")
else:
break
s.close()
if "HTTP/1.1 200 OK" in ret:
return (True,ret)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment