代理似乎被Mechanize忽略了?

编程入门 行业动态 更新时间:2024-10-22 04:46:38
本文介绍了代理似乎被Mechanize忽略了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用http代理和Mechanize模块.我初始化机械对象并按如下所示设置代理:

I am using an http proxy and the Mechanize module. I initialize the mechanize object and set the proxy like so:

self.br = mechanize.Browser() self.br.set_proxies({"http": proxyAddress}) #proxy address is like 1.1.1.1:8080

然后我像这样打开网站:

Then I open the site like so:

response = self.br.open("google")

我的问题是机械化似乎完全忽略了代理.如果我调试并检查br对象,则在代理处理程序下可以看到我的代理设置.但是,即使我给出了不好的代理,Mechanize也像我从未设置代理一样进行业务.有什么作用?

My problem is that mechanize seems to be completely ignoring the proxy. If I debug and inspect the br object, under the proxy handler I can see my proxy settings. However, even if I give a bad proxy Mechanize just goes about its business like I never set a proxy. What gives?

我也尝试过:

mechanize.install_opener(mechanize.build_opener(mechanize.ProxyHandler({'http': "127.0.0.1:99"}))) response = mechanize.urlopen("google")

似乎也忽略了我的代理. (我什至没有给它提供有效的代理,它是否不会因为URLError而失败?)

And it seems to be ignoring my proxy as well. (I didn't even give it a valid proxy, shouldn't it fail on a URLError?)

推荐答案

在电子邮件列表上进行讨论后将其弄清楚:

Figured it out after talking on the email list:

import mechanize browser = mechanize.Browser() browser.set_proxies(proxies={"http": "myproxy.example:1234"}, proxy_bypass=lambda hostname: False)

更多推荐

代理似乎被Mechanize忽略了?

本文发布于:2023-11-24 09:01:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624574.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:忽略了   Mechanize

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!