当前位置:首页 > Windows程序 > 正文

会给你一个API KEY和一个SECRET KEY

2024-03-31 Windows程序

先到百度云申请文字识别API ,,会给你一个API KEY和一个SECRET KEY,免费,一天最多500次请求。

技术分享图片


try:
temp_url = ‘https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【API KEY】&client_secret=【SECRET KEY】‘
temp_res = requests.post(temp_url)
temp_token = eval(temp_res.text)[‘access_token‘]
temp_url = ‘https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=‘ + temp_token
temp_headers = {‘Content-Type‘: ‘application/x-www-form-urlencoded‘}
temp_file = open(‘code_xjtu.png‘, ‘rb‘)
temp_image = temp_file.read()
temp_file.close()
temp_data = {
‘image‘: base64.b64encode(temp_image)
}
temp_data = urllib.parse.urlencode(temp_data)
temp_res = requests.post(url=temp_url, data=temp_data, headers=temp_headers)
code = int(eval(temp_res.text)[‘words_result‘][0][‘words‘])
except Exception as e:
print(e)
print(‘验证码识别异常,请联系打点员‘)

百度 验证码识别API 使用

标签:

原文地点:https://www.cnblogs.com/zealousness/p/8953714.html

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/33491.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494585访问次数
  • 建站天数
  • 友情链接