python requests證書問題解決
用requests包請求https的網(wǎng)站時,我們偶爾會遇到證書問題。也就是常見的SSLerror,遇到這種問題莫慌莫慌。
這里沒有找到合適的網(wǎng)站去報SSL證書的錯誤,所以就假裝請求了一個https的網(wǎng)站,然后給報了SSLerror了,然后下面是解決方法
可以直接關(guān)閉驗證ssl證書
import requests
'''
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param verify: (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to ``True``.
'''
r = requests.get('https://kyfw.12306.cn',verify=False)
print(r.text)
這種方式直接在函數(shù)里面加如verify改變Ture或者False即可,因為post與get調(diào)用的都為request()函數(shù),所以get與post都一樣。
如果這種方式奏效就用這種方式,如果不奏效就用下面的一種
import requests
'''
:param verify: (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to ``True``.
'''
## 證書路徑
cert = '../cert/test.pem'
r = requests.get('https://kyfw.12306.cn',verify=cert)
print(r.text)
就用這種,直接把證書的路徑丟給verify,請求即可
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python網(wǎng)絡(luò)編程中urllib2模塊的用法總結(jié)
使用urllib2模塊進行基于url的HTTP請求等操作大家也許都比較熟悉,這里我們再深入來了解一下urllib2針對HTTP的異常處理相關(guān)功能,一起來看一下Python網(wǎng)絡(luò)編程中urllib2模塊的用法總結(jié):2016-07-07
Python實戰(zhàn)之實現(xiàn)簡單的名片管理系統(tǒng)
這篇文章主要介紹了Python實戰(zhàn)之實現(xiàn)簡單的名片管理系統(tǒng),文中有非常詳細的代碼示例,對正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04
詳解python3中用HTMLTestRunner.py報ImportError: No module named ''
這篇文章主要介紹了詳解python3中用HTMLTestRunner.py報ImportError: No module named 'StringIO'如何解決,感興趣的可以了解一下2019-08-08

