用 Python 的 re 模块,或者 字符串方法 str.split() 。
def get_access_token():
url = 'https://aip.baidubce.com/oauth/2.0/token'
data = {
'grant_type': 'client_credentials', # 固定值
'client_id': '替换成你的API Key', # 在开放平台注册后所建应用的API Key
'client_secret': '替换成你的Secret Key' # 所建应用的Secret Key
}
res = requests.post(url, data=data)
res = res.json()
access_token = res['access_token']
return access_token