Feed date scraper for Gemini (protocol)
gemini request: wrap more in try block
Zach DeCook 2021-02-19
parent 0589ac0 · commit 495e6f4
-rwxr-xr-xzachwalk.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/zachwalk.py b/zachwalk.py
index 0e5feb6..6da89c4 100755
--- a/zachwalk.py
+++ b/zachwalk.py
@@ -15,14 +15,14 @@ def getnewestdate(url):
hostname = url.split('/')[2]
try:
s = socket.create_connection((hostname, 1965),timeout=2)
+ 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"))
+ fp = s.makefile("rb")
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"))
- fp = s.makefile("rb")
header = fp.readline()
header = header.decode("UTF-8").strip()
# TODO: something special if status is not 2x