如何修复在Python中使用requests库时出现的“ProxyError: 无法连接到代理,隧道连接失败: 403 Forbidden”?
我正在做一个自己的小项目,选择了www.pythonanywhere.com来托管它。
为了实现一些功能,我需要从网站上获取信息。
但是当我运行下面的代码时,
import requests
response = requests.get(
"https://example.com",
proxies={"http":"http://162.120.71.11:80"},
headers={"User-Agent": "Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.2.15 Version/10.00"}
)
print( response.text )
我遇到了一个错误。
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', O
SError('Tunnel connection failed: 403 Forbidden')))
我尝试更改用户代理和代理服务器,但没有任何变化。
我还尝试向不同的网站发送请求,有些网站可以正常工作,但我需要的网站却不行。