From 6a23df8c90cd3def49f83a68b501f785eefc6b37 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 26 Dec 2018 17:24:53 -0800 Subject: Don't use tor when logging in --- server.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index 647accf..90a318e 100644 --- a/server.py +++ b/server.py @@ -7,7 +7,7 @@ from youtube.youtube import youtube import http_errors import urllib import socket -import socks +import socks, sockshandler import subprocess import re @@ -41,8 +41,15 @@ def proxy_site(env, start_response): url = "https://" + env['SERVER_NAME'] + env['PATH_INFO'] if env['QUERY_STRING']: url += '?' + env['QUERY_STRING'] + + req = urllib.request.Request(url, headers=headers) - response = urllib.request.urlopen(req, timeout = 10) + if settings.route_tor: + opener = urllib.request.build_opener(sockshandler.SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9150)) + response = opener.open(req, timeout=10) + else: + response = urllib.request.urlopen(req, timeout=10) + start_response('200 OK', response.getheaders() ) return response.read() @@ -141,11 +148,6 @@ def site_dispatch(env, start_response): -if settings.route_tor: - #subprocess.Popen(TOR_PATH) - socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150) - socket.socket = socks.socksocket - gevent.socket.socket = socks.socksocket if settings.allow_foreign_addresses: server = WSGIServer(('0.0.0.0', settings.port_number), site_dispatch) -- cgit v1.2.3