pythonrequests证书_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í)有所幫助,也希望大家多多支持我們。
本文標(biāo)題: python requests證書問題解決
本文地址: http://www.cppcns.com/jiaoben/python/272431.html
總結(jié)
以上是生活随笔為你收集整理的pythonrequests证书_python requests证书问题解决的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓图标_干货 | 安卓界面系统规范
- 下一篇: python制作收费标准_在Python