質問

I am currently using Python + Mechanize for retrieving pages from a local server. As you can see the code uses "localhost" as a proxy. The proxy is an instance of the Fiddler2 debug proxy. This works exactly as expected. This indicates that my machine can reach the test_box.

import time
import mechanize

url = r'http://test_box.test_domain.com:8000/helloWorldTest.html'
browser = mechanize.Browser();
browser.set_proxies({"http": "127.0.0.1:8888"})
browser.add_password(url, "test", "test1234")

start_timer = time.time()

resp = browser.open(url)
resp.read()

latency = time.time() - start_timer

However when I remove the browser.set_proxies statement it stops to work. I get an error <"urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>". The point is that I can access the test_box from my machine with any browser. This also indicates that test_box can be reached from my machine.

My suspicion is that this has something to do with Mechanize trying to guess the proper proxy settings. That is: my Browsers are configured to go to a web proxy for any domain but test_domain.com. So I suspect that mechanize tries to use the web proxy while it should actually not use the proxy.

How can I tell mechanize to NOT guess any proxy settings and instead force it to try to connect directly to the test_box?

役に立ちましたか?

解決

Argh, found it out myself. The docstring says:

"To avoid all use of proxies, pass an empty proxies dict."

This fixed the issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top