0

I am using the following code found on post, How to specify an authenticated proxy for a python http connection?

import urllib2

def get_proxy_opener(proxyurl, proxyuser, proxypass, proxyscheme="http"):
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None, proxyurl, proxyuser, proxypass)

    proxy_handler = urllib2.ProxyHandler({proxyscheme: proxyurl})
    proxy_auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)

    return urllib2.build_opener(proxy_handler, proxy_auth_handler)

if __name__ == "__main__":
    import sys
    if len(sys.argv) > 4:
        url_opener = get_proxy_opener(*sys.argv[1:4])
        for url in sys.argv[4:]:
            print url_opener.open(url).headers
    else:
        print "Usage:", sys.argv[0], "proxy user pass fetchurls..."

I am using the proxy ip as specified in my wpad.dat file for argv[1]. (# for confidentiality)

return "PROXY 138.84.###.###:####";

I am using my username and password for argval[2] and [3]. When I use http://google.com it spits out the appropriate header information. When I use http://shipcsx.com/pub_sx_mainpagepublic_jct/sx.shipcsxpublic/Main it shows: HTTP Error 407: Proxy Authentication Required.

Community
  • 1
  • 1
Dennis
  • 51
  • 1
  • 8

1 Answers1

0

This may not be a question for StackExchange. You may need some visibility into your proxy server to troubleshoot properly. With no other information, I'll take an offhand guess that the Google domain (or part of it) is configured as a trusted site at the proxy. This allows a request to bypass proxy authentication entirely.

paidhima
  • 2,312
  • 16
  • 13
  • Thank you, that is probably why Google works but not ShipCSX. I would argue that this does belong on SO though because my question is why the code does not properly authenticate me. I was merely adding Google.com for further information. – Dennis Apr 23 '15 at 15:12
  • The good thing about HTTP errors is that they are frequently pretty descriptive in that they at least tell you where to look for issues. Assuming your proxy credentials were correct (which we couldn't tell you), the next step is to talk to the proxy server admin for more information. Your code looks perfectly fine, but we can't tell you why it won't authenticate. – paidhima Apr 23 '15 at 16:32