M protocol/gemini.py => protocol/gemini.py +2 -2
@@ 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":
M protocol/http.py => protocol/http.py +4 -1
@@ 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)