无法让 python 请求与代理一起工作 [英] Can't get python requests to work with proxies
问题描述
我正在尝试通过代理服务器执行一个简单的获取请求:
I am trying to do a simple get request through a proxy server:
import requests
test=requests.get("http://google.com", proxies={"http": "112.5.254.30:80"})
print test.text
代码中代理服务器的地址只是来自互联网上一些免费提供的代理列表.关键是当我从浏览器使用它时,这个相同的代理服务器可以工作,但它在这个程序中不起作用.我尝试了许多不同的代理服务器,但没有一个可以通过上述代码工作.
The address of the proxy server in the code is just from some freely available proxy lists on the internet. The point is that this same proxy server works when I use it from browser, but it doesn't work from this program. And i tried many different proxy servers and none of them works through above code.
这是我为这个代理服务器得到的:
Here is what I get for this proxy server:
无法检索请求的 URL
尝试检索 URL 时:http:///
遇到以下错误:
无法从 的主机名确定 IP 地址
The requested URL could not be retrieved
While trying to retrieve the URL: http:///
The following error was encountered:
Unable to determine IP address from host name for
dnsserver 返回:
无效的主机名
这意味着:缓存无法解析URL 中显示的主机名.检查地址是否正确.
This means that: The cache was not able to resolve the hostname presented in the URL. Check if the address is correct.
推荐答案
我知道这是一个老问题,但应该是
I know its an old question, but it should be
import requests
test=requests.get("http://google.com", proxies={"http":"http://112.5.254.30:80","https": "http://112.5.254.30:80"})
print (test.text)
这篇关于无法让 python 请求与代理一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!