From 8d746b120c755abb3fccba0e9be7291d35e4aa5c Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Thu, 18 Jun 2020 22:58:39 -0400 Subject: [PATCH] Catch errors silently. What happens in Vegas stays in Vegas. --- dehttps-proxy.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dehttps-proxy.py b/dehttps-proxy.py index 9ad2aae..7918b37 100755 --- a/dehttps-proxy.py +++ b/dehttps-proxy.py @@ -6,7 +6,7 @@ # # Bobbi June 2020 # -# If this client is running on port 8000, then fetching: +# If this client is running on raspberrypi:8000, then fetching URL: # http://raspberrypi:8000/www.google.com # Will fetch https://www.google.com # @@ -24,12 +24,17 @@ class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): url = 'https:/' + self.path print('Getting {} ...'.format(url)) - file = requests.get(url, allow_redirects=True) - self.send_response(200) - self.send_header("Content-type", "text/html") - self.send_header("Content-length", len(file.content)) - self.end_headers() - self.wfile.write(file.content) + err = False + try: + file = requests.get(url, allow_redirects=True) + except: + err = True + if err == False: + self.send_response(200) + self.send_header("Content-type", "text/html") + self.send_header("Content-length", len(file.content)) + self.end_headers() + self.wfile.write(file.content) handler = MyHTTPRequestHandler httpd = socketserver.TCPServer(("", PORT), handler)