python识别文字并标示位置_文字识别iocr通用版python报错

# -*- coding:UTF-8 -*-

# -*- encoding: utf-8 -*-

import base64

import requests

from urllib.parse import quote

headers = {

'Content-Type': "application/x-www-form-urlencoded",

'charset': "utf-8"

}

if __name__ == '__main__':

recognise_api_url = "https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise"

access_token = "mytoken"

templateSign = "c405e86ebc3daa9b04ae9d57ddd68c09"

classifierId = "your_classifier_id"

# 测试数据路径

image_path = "w2.jpeg"

try:

with open(image_path, 'rb') as f:

image_data = f.read()

image_b64 = base64.b64encode(image_data).replace("\r", "")

# 请求模板的bodys

recognise_bodys = "access_token=" + access_token + "&templateSign=" + templateSign + \

"&image=" + quote(image_b64.encode("utf8"))

# 请求分类器的bodys

classifier_bodys = "access_token=" + access_token + "&classifierId=" + classifierId + \

"&image=" + quote(image_b64.encode("utf8"))

# 请求模板识别

response = requests.post(recognise_api_url, data=recognise_bodys, headers=headers)

# 请求分类器识别

# response = requests.post(recognise_api_url, data=classifier_bodys, headers=headers)

print(response.text)

except Exception as e:

测试报错:a bytes-like object is required, not 'str'

请各位大神帮看一下问题出在哪里,不是已经转换bytes了吗 怎么还报这个错,并且这代码是官方写好的示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值