- 看到实验室的小可爱在玩,所以索性也就试了一下
- 这个只是其中的识别图片中文字的api调用测试
import requests;
import base64;
askurl = 'https://aip.baidubce.com/oauth/2.0/token'
data={
'grant_type':'client_credentials',
'client_id':'xxx',
'client_secret':'xxx'
}
request = requests.post(askurl,data=data)
assess_token=eval(request.text)['access_token']
url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/webimage?access_token='+assess_token
headers={
'Content-Type':'application/x-www-form-urlencoded',
}
f = open('1.png','rb')
img = base64.b64encode(f.read())
params={
'image':img
}
request = requests.post(url,data=params,headers=headers)
if (request.content):
print(request.content.decode())
- 所用图片:
- 结果