python图像识别植物识别_python 植物识别 error_code

错误代码:{'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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值