Closed viponedream closed 3 years ago
我使用 了ImageBase64 就出错. 用 ImageUrl就正常。 请问这个 ImageBase64 要怎么使用才行?
image = './1.png' with open(image, "rb") as f: # 转为二进制格式 base64_data = base64.b64encode(f.read()) # 使用base64进行加密
cred = credential.Credential(SECRET_ID, SECRET_KEY) httpProfile = HttpProfile() httpProfile.endpoint = "ocr.tencentcloudapi.com"
clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = ocr_client.OcrClient(cred, "ap-guangzhou", clientProfile)
req = models.GeneralAccurateOCRRequest() req.ImageBase64 = base64_data
resp = client.GeneralAccurateOCR(req) print(resp.to_json_string())
是python3环境吗?具体报什么错误?
参考下这个测试用例看看?https://github.com/TencentCloud/tencentcloud-sdk-python/blob/master/tests/integration/ocr/test_general_accurate_ocr.py
req.ImageBase64 = base64_data 返回的类型是bytes, 但是这里需要str,源代码可以修改为 req.ImageBase64 = base64_data.decode('utf-8')
req.ImageBase64 = base64_data
req.ImageBase64 = base64_data.decode('utf-8')
请注意在python2和python3中, 字符串默认的类型是不一样的, 具体可以参考上述提到的sdk测试用例
我使用 了ImageBase64 就出错. 用 ImageUrl就正常。 请问这个 ImageBase64 要怎么使用才行?
image = './1.png' with open(image, "rb") as f: # 转为二进制格式 base64_data = base64.b64encode(f.read()) # 使用base64进行加密
cred = credential.Credential(SECRET_ID, SECRET_KEY) httpProfile = HttpProfile() httpProfile.endpoint = "ocr.tencentcloudapi.com"
clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = ocr_client.OcrClient(cred, "ap-guangzhou", clientProfile)
req = models.GeneralAccurateOCRRequest() req.ImageBase64 = base64_data
resp = client.GeneralAccurateOCR(req) print(resp.to_json_string())