win下本地运行代码 使用的是py3.7.0
import requests
from bs4 import BeautifulSoup
urls = "http://www.weather.com.cn/weather/101010100.shtml"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
# 本地测试链接仍然打不开
r = requests.get(urls, timeout=30, headers=headers)
r.raise_for_status() # 若请求不成功,抛出HTTPError 异常
r.encoding = 'utf-8'
soup = BeautifulSoup(r.text, "html.parser")
print(soup)
报错requests.exceptions.SSLError: HTTPSConnectionPool(host='http://www.weather.com.cn%27/, port=443): Max retries exceeded with url: /weather/101010100.shtml (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1045)')))
可有知晓,疑似本地环境有关,无奈实在找不到办法,代码设置过 os.environ['COMPOSE_TLS_VERSION'] = "TLSv1_2" 仍不起效