为什么我的 Python 程序没有到达预期的网站?

Why doesn't my Python program reach the intended website?

我正在尝试在 Python 中制作网络抓取工具 3. 我一直收到 WinError 10060 提示连接失败,因为连接方没有正确响应或连接的主机没有响应。同时使用 urllib 并尝试使用请求库都会产生 10060 错误。使用请求时,错误状态是 URL 超出了最大重试次数。

import urllib.request

with urllib.request.urlopen('http://python.org') as response: 
    html = response.read()

人们提到这可能是代理或防火墙问题,因为我正试图在我的工作网络上执行此操作。

原来这是代理身份验证错误。只需在 get 命令中使用您的凭据添加代理即可解决此问题。

proxies = {'http': 'http://user:pass@url:8080', 'https': 'http://user:pass@url:8080'}
page = requests.get(webpage, proxies)