我收到以下错误:请求.异常.代理错误:



我正在运行这个简单的代码:

import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)

然而,我得到这个错误

requests.exceptions.ProxyError: HTTPSConnectionPool(host='w3schools.com', port=443): Max retries exceeded with url: /python/demopage.htm (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)'))))

我该如何解决这个问题?

我实际上遇到了代理问题。所以我只是为https和http设置了代理dict,并将代理作为参数传递,如下所示:

import requests
proxies = {
'http': '*********',
'https': '*********',
}
x = requests.get('https://w3schools.com/python/demopage.htm', proxies =proxies )
print(x.text)

运行良好,没有任何问题。

import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)

输出:

<html>
<body>
<h1>This is a Test Page</h1>
</body>
</html>