Using an HTTP PROXY - Python - Stack Overflow
Using an HTTP PROXY - Python
You can do it even without the HTTP_PROXY environment variable. Try this sample:
import urllib2 proxy_support = urllib2.ProxyHandler({"http":"http://61.233.25.166:80"}) opener = urllib2.build_opener(proxy_support) urllib2.install_opener(opener) html = urllib2.urlopen("http://www.google.com").read() print html
In your case it really seems that the proxy server is refusing the connection.
Something more to try:
import urllib2 #proxy = "61.233.25.166:80" proxy = "YOUR_PROXY_GOES_HERE" proxies = {"http":"http://%s" % proxy} url = "http://www.google.com/search?q=test" headers={'User-agent' : 'Mozilla/5.0'} proxy_support = urllib2.ProxyHandler(proxies) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler(debuglevel=1)) urllib2.install_opener(opener) req = urllib2.Request(url, None, headers) html = urllib2.urlopen(req).read() print html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步