使用 requests 库在 Python 中发出请求时如何修复“ProxyError: Cannot connect to proxy, Tunnel connection failed: 403 Forbidden”?

问题描述 投票:0回答:1

我正在开发我的宠物项目,并选择 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')))

我尝试更改用户代理和代理,但没有任何改变

我还尝试向不同的网站发出请求,对于某些网站它有效,但不适用于我需要的网站

python https python-requests proxy request
1个回答
0
投票

我也遇到了同样的问题,如果您使用免费计划,该域名似乎需要位于白名单中:

https://www.pythonanywhere.com/forums/topic/27261/

© www.soinside.com 2019 - 2024. All rights reserved.