Code Monkey home page Code Monkey logo

Comments (5)

zqfan avatar zqfan commented on August 19, 2024

要看具体接口的说明。或者直接提工单给所使用的产品排查一下。
一般而言,无法读取本地数据可能有:1)本地文件已损坏;2)代码读取时有错误,并非二进制数据;3)传值给sdk时有问题,sdk的参数期望的是字符串或base64后的字符串;4)自己添加了不必要的格式头而不是文件原本的数据。网络上的数据下载失败可能有:1)需要特殊的网络权限或者代理等;2)文件太大下载超时;3)格式不对。
腾讯云上的图像数据至少能排除掉网络方面的故障。

from tencentcloud-sdk-python.

PoJason avatar PoJason commented on August 19, 2024

是否可以提供一个是使用图像base64编码数据, 通过params传给SDK?

from tencentcloud-sdk-python.

PoJason avatar PoJason commented on August 19, 2024

picFilePath = "../images/print_scan_en.png"
f = open(picFilePath, 'rb') # 二进制方式打开图文件
q = base64.b64encode(f.read()).decode('utf-8') # 读取文件内容,转换为base64编码
f.close()

try:
cred = credential.Credential("", "")
httpProfile = HttpProfile()
httpProfile.endpoint = "ocr.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ocr_client.OcrClient(cred, "ap-guangzhou", clientProfile)

req = models.GeneralHandwritingOCRRequest()
params = '{"ImageBase64": f}'
req.from_json_string(params)

resp = client.GeneralHandwritingOCR(req)
print(resp.to_json_string())

except TencentCloudSDKException as err:
print(err)

其中: params应该是str类型, 但f本身内容就无法知道了, 如果params是dict的话, 解析报错

from tencentcloud-sdk-python.

zqfan avatar zqfan commented on August 19, 2024

你填f显然就错了啊,不是应该填q吗?
编码命名习惯可以改善下,不然容易把自己都绕进去还不容易看出毛病

from tencentcloud-sdk-python.

PoJason avatar PoJason commented on August 19, 2024

多谢指出! 确实是应该填写为q, (Linux环境) params那行正确的写法是: params = '{"ImageBase64": "%s"}' % q

from tencentcloud-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.