From d67d5010d190b15b8cb0eb3da4209b07061c3f01 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 7 Dec 2015 15:03:53 -0800 Subject: [PATCH] Catch exception that occurs when stopping a web app that has not started (fixes #237) --- onionshare/web.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/onionshare/web.py b/onionshare/web.py index 89565810..623509a4 100644 --- a/onionshare/web.py +++ b/onionshare/web.py @@ -279,11 +279,14 @@ def stop(port): Stop the flask web server by loading /shutdown. """ # to stop flask, load http://127.0.0.1://shutdown - if transparent_torification: - import socket + try: + if transparent_torification: + import socket - s = socket.socket() - s.connect(('127.0.0.1', port)) - s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug)) - else: - urllib2.urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read() + s = socket.socket() + s.connect(('127.0.0.1', port)) + s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug)) + else: + urllib2.urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read() + except: + pass