Python urllib2 proxy setting issue
<p>I've looked through some of the other posts on this and I hope I'm not duplicating, but I'm stuck on a real headscratcher with setting a proxy server for urllib2. I'm running the below: </p>

<pre><code>    file, site = argv
    uri = 'https://'+site
    http_proxy_server = "http://newyork.wonderproxy.com"
    http_proxy_port = "11001"
    http_proxy_user = "user"
    http_proxy_passwd = "password"

    http_proxy_full_auth_string = "http://%s:%s@%s:%s" % (http_proxy_user,
                                                          http_proxy_passwd,
                                                          http_proxy_server,
                                                          http_proxy_port)

    proxy_handler = urllib2.ProxyHandler({"http": http_proxy_full_auth_string})
    opener = urllib2.build_opener(proxy_handler)
    urllib2.install_opener(opener)
    html = opener.open(uri).read()
    print html, 'it opened!'
</code></pre>

<p>I'm running this against an IP info site, but try as I might the response always comes out with my non-proxy IP address. When I manually set my proxy through system settings I do get a different response, so I've confirmed it's not an issue with the proxy criteria itself.</p>

<p>Any help that could be offered would be much appreciated!</p>

<p>Well this is a bit silly, but I tried a different example and my connection is working fine now.</p>

<pre><code>    import urllib2

    proxlist= ['minneapolis.wonderproxy.com', 'newyork.wonderproxy.com']
    ports = [0,1,2,3]
    for prox in proxlist:
        for port in ports:
            proxy = urllib2.ProxyHandler({'http': 'http://user:password@%s:1100%s'%(prox,port)})
            auth = urllib2.HTTPBasicAuthHandler()
            opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
            urllib2.install_opener(opener)
            try: 
                conn = urllib2.urlopen('http://www.howtofindmyipaddress.com/')
                return_str = conn.read()
                str_find = '&lt;span style="font-size: 80px; color: #22BB22; font-family: Calibri,Arial;"&gt;'
                strt = return_str.find(str_find)+len(str_find)
                print prox, port, return_str[strt:return_str.find('&lt;/span',strt)-1]
            except urllib2.URLError:
                print prox, port, 'That\'s a no go'
</code></pre>

<p>Only difference I can see is that the second one used HTTPHandler instead of Proxy, as I have an apparently solution I'm not too worried, but woudl still be interested to know why I had this issue in the first place.</p>

python proxy urllib2