import urllib2
proxy = urllib2.ProxyHandler({ "http" : "http:proxyIp1", "https" : "proxyIp2"})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
try:
a = urllib2.urlopen("corporate internal link")#, proxies=proxy)
b = a.read()
except urllib2.HTTPError as e:
error = e.read() # this will be your error message
print error
这给出了一个错误:
401 - Unauthorized: Access is denied due to invalid credentials.
我知道我必须提供“用户名”和“密码”,但任何人都可以告诉我在这种情况下如何提供凭据?谢谢