Why am I getting this error? HTTP Error 407: Proxy

2019-09-06 21:12发布

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.

1条回答
Ridiculous、
2楼-- · 2019-09-06 21:48

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.

查看更多
登录 后发表回答