Python 代理请求因 WinError 10060 失败

Python requests with proxy failing for WinError 10060

我正在尝试使用代理向 Python 发起一些请求,但没有成功。我不知道我做错了什么,这个错误对我来说意义不大。下面是我使用的代码:

proxy_url = 'us6277.nordvpn.com'
auth = (username, password)
proxies = {
    'http': proxy_url,
    'https': proxy_url,
}
requests.get('https://google.com', proxies=proxies, auth=auth)

我得到的错误是

requests.exceptions.ProxyError: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000014C006414C0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))

您尝试连接到端口 443 上的 google.com 失败,超过最大重试次数: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url

这是由于: ProxyError('Cannot connect to proxy. NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000014C006414C0>: Failed to establish a new connection:

具体原因: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond(您的代理未能响应)

问题是您尝试连接到代理无效。您将 auth=auth 传递给对 requests.get() 的调用,这是放置代理身份验证凭据的错误位置。 Here's the documentation on proxies for requests。您需要以 'http': 'http://username:password@us6277.nordvpn.com/' 格式提供您的凭据。