我正在尝试创建一个代理测试员,我已经尝试了好几天解决这个问题,但似乎无法解决这个问题。每次我运行它时,无论代理是什么(我已经尝试了很多次),我都会得到错误
"requests.exceptions.ProxyError: HTTPSConnectionPool(host='advanced.name', port=443): Max retries exceeded with url: /freeproxy (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9a7e0ea400>: Failed to establish a new connection: [Errno -2] Name or service not known')))"
消息听起来像是代理坏了,但我已经尝试了一个船负载,我知道工作。这是我的密码
import requests
from requests.exceptions import Timeout
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-GB,en;q=0.5',
'DNT': '1',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
}
proxy = {
"http": "http//132.145.54.142:1080",
"https": "https//132.145.54.142:1080"
}
proxy_Test = requests.get("https://advanced.name/freeproxy", headers=headers, proxies=proxy, timeout=10)
print(proxy_Test.status_code)
if proxy_Test.status_code == 200:
print("this proxy is good:" + str(proxy).replace("{", " ").replace("}", "").replace("'", ""))
else:
print("This proxy is no good")
try:
x = requests.get("http://www.google.com", headers=headers, proxies=proxy, timeout=10)
except Timeout:
print("error found")
此网站在您所在的国家/地区进行筛选,您设置的代理:
也不起作用,因此您必须找到另一个代理
如果要隐藏ip地址,可以使用TorreRequest而不是请求:
示例代码(more here):
您需要先安装Tor browser
相关问题 更多 >
编程相关推荐