Catch errors silently. What happens in Vegas stays in Vegas.

This commit is contained in:
Bobbi Webber-Manners 2020-06-18 22:58:39 -04:00
parent 2ac8ce06cd
commit 8d746b120c
1 changed files with 12 additions and 7 deletions

View File

@ -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)