开发者

Python mechanize module proxy setting question

It seems like 开发者_运维问答these codes would work:

MechBrowser = mechanize.Browser()
MechBrowser.set_proxies({"http": "111.11.11.11"})
response = MechBrowser.open("http://google.com")

But as you see "111.11.11.11" is just a random ip I came up with to test if the proxy setting works, and it's not a valid proxy. The weird thing is MechBrowser still open google.com without giving any error, so does this mean if the proxy you set not working mechanize will use default setting to browse? If I want it to throw exception when the proxy is broken, how should I do?

Thanks a lot


Syntax is ok, and its working on my machine as it should do.

------> print(mechanize.__version__)
(0, 2, 1, None, None)

>python -V
Python 2.6.5

When proxy is unavailable, for example, it will raise URLError. I can recommend you to check the version of mechanize+python you`re using at the moment and run this code in python interpreter interactively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜