天天看點

HTTPSConnectionPool(host=‘m.weibo.cn‘, port=443): Max retries exceeded with url: /api/container/getI

問題:爬取微網誌資料時,報錯: HTTPSConnectionPool(host='m.weibo.cn', port=443): Max retries exceeded with url: /api/container/getIndex?type=uid&value=1935317321&containerid=1076031935317321&page=141 (Caused by SSLError(SSLError(1, '[SSL: BAD_SIGNATURE] bad signature (_ssl.c:1108)')))

原因:requests請求時證書認證失敗

解決:

1.在請求參數中将verify修改為False,目的:使requests忽略對SSL證書的驗證。即

response = requests.get(url=url,headers=headers,verify= False)
           

2.在導包處添加兩條語句,目的:解除安全警告。即

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
           

如圖所示:

圖1

HTTPSConnectionPool(host=‘m.weibo.cn‘, port=443): Max retries exceeded with url: /api/container/getI

圖2

HTTPSConnectionPool(host=‘m.weibo.cn‘, port=443): Max retries exceeded with url: /api/container/getI