嗨,我写了几行简单的代码。但我似乎遇到了身份验证错误。任何人都可以建议,这里正在寻找 python 的哪些凭据?
代码:
import urllib2
response = urllib2.urlopen('http://google.com')
html = response.read()
错误
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required
PS:我没有访问 IE --> 高级设置或regedit
根据建议,我已经修改了代码:
import urllib2
proxy_support = urllib2.ProxyHandler({'http':r'http://usename:psw@IP:port'})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy_support, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
response = urllib2.urlopen('http://google.com')
html = response.read()
我还创建了两个环境变量:
HTTP_PROXY = http://username:password@proxyserver.domain.com
HTTPS_PROXY = https://username:password@proxyserver.domain.com
但仍然得到错误。
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required