在 python 中为 http 连接指定具有用户名和密码的代理的最佳方法是什么?
最佳答案
这对我有用:
import urllib2
proxy = urllib2.ProxyHandler({'http': 'http://
username:password@proxyurl:proxyport'})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
conn = urllib2.urlopen('http://python.org')
return_str = conn.read()
关于python - 如何为 python http 连接指定经过身份验证的代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34079/