1、python直接忽略证书进行https访问(有警告信息)
将请求的verify设置为False,详细请求如下:
# -*- coding:utf-8 -*-
import pymysql
import sys
import requests
import sys
import time
import json
reload(sys)
sys.setdefaultencoding( "utf-8" )
def gettoken():
url = 'https://www.td.com/getToken'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {'client_id':'abc',
'client_secret':5165325',
'grant_type':'client_credentials'
}
session = requests.Session()
session.verify = False
res = requests.post(url,headers=headers,data=data)
return res.json()['access_token']
access_token = gettoken()
print(access_token)
此时会有以下警告信息:
2、python直接忽略证书进行https访问(无警告信息)
如果不想有警告信息,导入urllib3,调用下面方法,即可不显示警告信息。
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)