python 植物识别 error_code
无为ott 发布于2020-07 浏览:1129 回复:3
0
收藏

错误代码:{'error_code': 110, 'error_msg': 'Access token invalid or no longer valid'}

有Access token生成,但是后面一直是错误。。。。

code:

# encoding:utf-8

import requests
import base64

'''
植物识别
'''

# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API Key}={Secret Key}'
response = requests.get(host)
mytoken = response.json()
print(mytoken)


request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant"
# 二进制方式打开图片文件
f = open("", "rb")
img = base64.b64encode(f.read())

params = {"image":img}
access_token = "mytoken"
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
print (response.json())

收藏
点赞
0
个赞
共3条回复 最后由Randcase回复于2020-07
#4Randcase回复于2020-07

token错误 这种报错已经提示很明显了

0
#3wangwei8638回复于2020-07

是否调用的不对

0
#2wangwei8638回复于2020-07

Access token打印出来看下

0
TOP
切换版块