From 419aafcf112fdb558f2a36fc4d92cd2b7ad2b936 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 20 Jan 2023 08:10:56 -0500 Subject: [PATCH] protocols: Show errors instead of hanging or hiding them --- protocol/gemini.py | 4 ++-- protocol/http.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/protocol/gemini.py b/protocol/gemini.py index b4cccbe..05f86ce 100644 --- a/protocol/gemini.py +++ b/protocol/gemini.py @@ -25,8 +25,8 @@ class GeminiProtocol(): s = context.wrap_socket(s, server_hostname = hostname) s.sendall((url + '\r\n').encode("UTF-8")) fp = s.makefile("rb") - except: - return ("text/error",["error"]) + except Exception as e: + return ("text/error",["error\n", str(e)]) header = fp.readline() header = header.decode("UTF-8").strip() if header[0:1] == "2": diff --git a/protocol/http.py b/protocol/http.py index 2f9672c..96428f9 100644 --- a/protocol/http.py +++ b/protocol/http.py @@ -1,5 +1,8 @@ import requests class HttpProtocol(): def get(url): - r = requests.get(url) + try: + r = requests.get(url, timeout=5) + except Exception as e: + return ("text/error", ["error\n", str(e)]) return (r.headers['content-type'].split(';')[0], r) -- 2.45.2