I want to pass all Python's traffics through a http proxy server, I checked urlib2 and requests packages for instance, they can be configured to use proxies but how could I use something like a system-wide proxy for Python to proxy all the data out?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Admittedly, this isn't exactly what you are looking for, but if you know the programmatic source of all your network traffic in your python code, you can do this proxy wrapping in the code itself. A pure python solution is suggested using the
PySocks
module in the following link:https://github.com/httplib2/httplib2/issues/22
Now every call made using
httplib2
will use those proxy settings. You should be able to wrap any networking module that uses sockets to use this proxy.https://github.com/Anorov/PySocks
They mention there that this isn't recommended, but it seems to be working fine for me.
Linux system first export the environment variables like this
or in the script that yo want to pass trough a proxy
then run python script
UPDATE
An also you can use redsocks whith this tool you can redirect silently all your TCP connections to a PROXY with or without authentication. But you have to take care because it's for all connections not only for the python.
Windows systems you can use tools like freecap, proxifier, proxycap, and configure to run behind the python executable