Broken project to implement a cross-protocol browser in textual
protocols: Show errors instead of hanging or hiding them
Zach DeCook 2023-01-20
parent 7682658 · commit 419aafc
-rw-r--r--protocol/gemini.py4
-rw-r--r--protocol/http.py5
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)