Python代理问题

发布于 2024-09-07 07:53:33 字数 133 浏览 1 评论 0原文

是否可以通过 HTTPS 或 SOCKS 代理过滤所有传出连接?我有一个使用各种 api 和 api 的脚本调用使用 mechanize/urllib 的脚本。我想通过代理过滤每个连接,在我的“主”脚本(调用所有 api 的脚本)中设置代理。这可能吗?

Is it possible to filter all outgoing connections through a HTTPS or SOCKS proxy? I have a script that users various apis & calls scripts that use mechanize/urllib. I'd like to filter every connection through a proxy, setting the proxy in my 'main' script (the one that calls all the apis). Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少跟Wǒ拽 2024-09-14 07:53:33

是的,您可以将其放入代码中或从环境中获取。

看这里 http://docs.python.org/library/urllib.html

proxies = {'http': 'http://www.someproxy.com:3128'}
filehandle = urllib.urlopen(some_url, proxies=proxies)

或者

$ http_proxy="http://www.someproxy.com:3128"
$ export http_proxy
$ python yourScript.py 

或者

$[tsocks][1] yourScript.py

Yes, you can put it in your code or take it from the environment.

Look here http://docs.python.org/library/urllib.html

proxies = {'http': 'http://www.someproxy.com:3128'}
filehandle = urllib.urlopen(some_url, proxies=proxies)

Or

$ http_proxy="http://www.someproxy.com:3128"
$ export http_proxy
$ python yourScript.py 

Or

$[tsocks][1] yourScript.py
生生漫 2024-09-14 07:53:33

就像 文档 所说, urllib.urlopen() 在系统中查找代理信息,并且还采用可选参数供代理使用。

Just like the docs say, urllib.urlopen() looks to the system for proxy information, and also takes an optional argument for the proxies to use.

苍景流年 2024-09-14 07:53:33

为了将 Tor 与 mechanize 结合使用,我使用 tor+polipo。
在confing文件中将polipo设置为使用父代理socksParentProxy=localhost:9050。
然后使用

browser.set_proxies({"http": "localhost:8118"}) ,

其中 8118 是你的 polipo 端口。

所以你正在使用 polipo http 代理,它使用 sock 来使用 tor

希望它有帮助:)

to use tor with mechanize I use tor+polipo.
set polipo to use parent proxy socksParentProxy=localhost:9050 at confing file.
then use

browser.set_proxies({"http": "localhost:8118"})

where 8118 is your polipo port.

so you are using polipo http proxy that uses sock to use tor

hope it helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文