diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-12-26 17:24:53 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-12-26 17:24:53 -0800 |
commit | 6a23df8c90cd3def49f83a68b501f785eefc6b37 (patch) | |
tree | 4e6eabc8fb964fc6fccf4947d8b5bbe9766debaa /server.py | |
parent | b321b5fc6484c38d861530e6b89405b062e32459 (diff) | |
download | yt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.tar.lz yt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.tar.xz yt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.zip |
Don't use tor when logging in
Diffstat (limited to 'server.py')
-rw-r--r-- | server.py | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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) |