From 6da92c8e58bda9976ca2693d5e9bf25ac2b9cb46 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sun, 7 Feb 2021 23:32:24 -0500 Subject: connection: timeout after 2 seconds --- zachwalk.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'zachwalk.py') diff --git a/zachwalk.py b/zachwalk.py index 2c2c3ea..a7d1a8d 100755 --- a/zachwalk.py +++ b/zachwalk.py @@ -12,13 +12,15 @@ def getnewestdate(url): """load the url, and find the newest date listed in a link""" # TODO: outsource to pre-installed cli program? hostname = url.split('/')[2] - s = socket.create_connection((hostname, 1965)) + try: + s = socket.create_connection((hostname, 1965),timeout=2) + except: + return DEFAULT context = ssl.SSLContext() context.check_hostname = False context.verify_mode = ssl.CERT_NONE s = context.wrap_socket(s, server_hostname = hostname) s.sendall((url + '\r\n').encode("UTF-8")) - # Get header and check for redirects fp = s.makefile("rb") header = fp.readline() header = header.decode("UTF-8").strip() -- cgit 1.4.1