开发者

Python mechanize module proxy setting question

开发者 https://www.devze.com 2023-01-23 20:19 出处:网络
It seems like 开发者_运维问答these codes would work: MechBrowser = mechanize.Browser() MechBrowser.set_proxies({\"http\": \"111.11.11.11\"})

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

精彩评论

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

关注公众号