Caused by SSLError
1 import requests 2 from bs4 import BeautifulSoup 3 4 5 def get_page(): 6 url = 'https://movie.douban.com/cinema/nowplaying/changsha/' 7 headers = { 8 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" 9 }10 response = requests.get(url, headers=headers) 11 text = response.text 12 return text 13 29 30 if __name__ == '__main__': 31 text = get_page() 32
程式執行報錯:requests.exceptions.SSLError: HTTPSConnectionPool(host='movie.douban.com', port=443): Max retries exceeded with url: /cinema/nowplaying/changsha/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),))
其實很奇怪,我昨天晚上的時候程式碼還正常運行了,今天竟然就報錯了,百度找到一個解決方法,原文內容:
python locust介面效能測試HTTPS網站報錯:Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certi
2017年12月13日 18:38:39 蓉兒Sharon 閱讀數:4115更多 個人分類: python 學習問題描述:
測試HTTPS SSL 協議的網站介面,用Python Locust模組,不論POST還是GET都提示錯誤:
SSLError
Max retries exceeded with url: /action.php?m=upload
(Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))",),)
後面查官網locust.io,終於找到解決方法:https://docs.locust.io/en/latest/api.html
request
(method, url, name=None, catch_response=False, **kwargs)
Constructs and sends a requests.Request
. Returns requests.Response
object.
Parameters: |
|
---|
這是HTTPS網站所做的SSL證書認證,預設是True的,設定為False之後對測試沒有影響;
當然如果知道證書的路徑,應該也可以用cert設定.pem檔案的路徑,也可以解決
######################################################################################################################################### 在程式碼第10行更改程式碼為response = requests.get(url, headers=headers, verify=False),程式可以正常執行。
另外找到其他的解決方法,可是才剛開始學,不知道怎麼使用。
另外的解決方法連結https://www.cnblogs.com/lykbk/p/ASDFQAWQWEQWEQWEQWEQWEQWEQEWEQW.html
https://blog.csdn.net/wangxiaotian2007/article/details/79284124