使用代理IP访问网站时出现的问题
使用代理IP代码大概如下:
proxy = {
‘http’:‘http://’ + proxy_host,
‘https’:‘https://’ + proxy_host
}
r = requests.get(url, proxies = proxy)
错误一:
requests.exceptions.ProxyError: HTTPSConnectionPool(host=‘stock2.finance.sina.com.cn’, port=443): Max retries exceeded with url: /futures/api/jsonp.php/=/InnerFuturesNewService.getFewMinLine?symbol=V2401&type=1 (Caused by ProxyError(‘Unable to connect to proxy. Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#https-proxy-error-http-proxy’, SSLError(SSLError(1, ‘[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1122)’))))
原因分析:
通过错误提示只使用HTTP而不使用HTTPS,因此将代理IP里面的HTTPS直接删掉即可。
修改如下:
proxy = {
‘http’:‘http://’ + proxy_host
}