0

I've got mechanize setup and working with python. I am adding support for using a proxy, but how do I check that I am actually using the proxy?

Here is some code I am using:

ip = 'some proxy ip address'
br.set_proxies({"http://": ip} )

I started to wonder if it was working because just to do some testing I typed in:

ip = 'asdfasdf'

and it didn't throw an error. So how do I go about checking if it is really using the ip address for the proxy that I pass in or the ip address of my computer? Is there a way to return info on your ip in mechanize?

1
  • If you use http:// as the key, then mechanize will not recognize it as a proxy type. You must use {"http": .....} Commented Jun 19, 2012 at 12:58

2 Answers 2

2

maybe like this ?

br = mechanize.Browser()
br.set_proxies({"http": '127.0.0.1:80'})

you need to debug for more information

br.set_debug_http(True)
br.set_debug_redirects(True)
Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure how to handle this issue with mechanize, but you could read the next link that explains how to do it without mechanize (but still in python):

Proxy Check in python

The simple solution provided at the above-mentioned link could be easily adapted to your needs.

Thus, instead of the line:

print "Connection error! (Check proxy)"

you could replace by

SucceededYesNo="NO"

and instead of

print "All was fine"

just replace by

SucceededYesNo="YES"

Now, you have a variable available for further processing.

I am however afraid this will not cover the cases when the target web page is down because the same error might occur out of two causes (so one would not know whether a NO outcome is coming from a not working proxy server or from a bad web page), but still could be a solution: what about to check with the above-mentioned code a working web page? i.e. www.google.com? In this way, you could eliminate one cause and it remains the other.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.