binux / pyproxy Goto Github PK
View Code? Open in Web Editor NEWHTTP(s) proxy server base on tornado, in one file!
HTTP(s) proxy server base on tornado, in one file!
环境:win7x64,python3.6.5 x86,tornado5.0.2
在IE中设置http代理访问www.baidu.com报错:
D:\>python pyproxy.py
[I 180625 16:57:01 pyproxy:441] http server started on 127.0.0.1:8888
[E 180625 16:57:05 http1connection:54] Uncaught exception
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\http1co
nnection.py", line 184, in _read_message
header_future = delegate.headers_received(start_line, headers)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\simple_
httpclient.py", line 458, in headers_received
self.request.header_callback('%s %s %s\r\n' % first_line)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\stack_c
ontext.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "pyproxy.py", line 252, in <lambda>
req.header_callback = lambda line, stream=stream: not stream.closed() an
d stream.write(line) if not line.startswith('Transfer-Encoding') else None
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\iostrea
m.py", line 530, in write
self._write_buffer.append(data)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\iostrea
m.py", line 156, in append
self._buffers.append((False, bytearray(data)))
TypeError: string argument without an encoding
[E 180625 16:57:05 ioloop:792] Exception in callback functools.partial(<function
wrap.<locals>.wrapped at 0x03968C90>, <Future finished exception=_QuietExceptio
n()>)
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\http1co
nnection.py", line 184, in _read_message
header_future = delegate.headers_received(start_line, headers)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\simple_
httpclient.py", line 458, in headers_received
self.request.header_callback('%s %s %s\r\n' % first_line)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\stack_c
ontext.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "pyproxy.py", line 252, in <lambda>
req.header_callback = lambda line, stream=stream: not stream.closed() an
d stream.write(line) if not line.startswith('Transfer-Encoding') else None
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\iostrea
m.py", line 530, in write
self._write_buffer.append(data)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\iostrea
m.py", line 156, in append
self._buffers.append((False, bytearray(data)))
TypeError: string argument without an encoding
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\ioloop.
py", line 759, in _run_callback
ret = callback()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\stack_c
ontext.py", line 344, in wrapped
raise_exc_info(exc)
File "<string>", line 4, in raise_exc_info
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\stack_c
ontext.py", line 315, in wrapped
ret = fn(*args, **kwargs)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\simple_
httpclient.py", line 395, in <lambda>
lambda f: f.result())
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\gen.py"
, line 1113, in run
yielded = self.gen.send(value)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\http1co
nnection.py", line 186, in _read_message
yield header_future
File "C:\Program Files (x86)\Python36-32\lib\site-packages\tornado\http1co
nnection.py", line 55, in __exit__
raise _QuietException
tornado.http1connection._QuietException
[I 180625 16:57:05 web:2106] 200 GET http://www.baidu.com/ (127.0.0.1) 107.01ms
直接运行访问某些网址无法代理
例如直接访问: localhost:8888/?method=get&url=http://www.qq.com
另外,这个proxy能整个过滤,过滤返回的页面内容,如 css、js、img等通过proxy来访问就更好了
实在懒得自己写代码了,拿来主义,请见谅
[I 210728 19:10:33 pyproxy:242] http server started on 127.0.0.1:8080
[E 210728 19:10:38 web:1789] Uncaught exception CONNECT <REDACTED>:443 (127.0.0.1)
HTTPServerRequest(protocol='http', host='<REDACTED>', method='CONNECT', uri='<REDACTED>:443', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/web.py", line 1704, in _execute
result = await result
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/gen.py", line 775, in run
yielded = self.gen.send(value)
File "/Users/sergius/work/venv/lib/python3.8/site-packages/pyproxy.py", line 208, in connect
fw = remote.set_close_callback(gen.Callback(remote))
AttributeError: module 'tornado.gen' has no attribute 'Callback'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/web.py", line 1217, in send_error
self.write_error(status_code, **kwargs)
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/web.py", line 1242, in write_error
self.finish(
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/web.py", line 1157, in finish
future = self.flush(include_footers=True)
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/web.py", line 1094, in flush
return self.request.connection.write_headers(
File "/Users/sergius/work/venv/lib/python3.8/site-packages/tornado/http1connection.py", line 456, in write_headers
if self.stream.closed():
AttributeError: 'NoneType' object has no attribute 'closed'
MacOS, virtualenv Python 3.8.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.