文字识别的HTTPS接口在处理图片(未超4M限制)时候返回图片格式错误,很小的图片时返回正常
a1370268 发布于2017-05 浏览:2856 回复:3
0
收藏

我使用的服务是:通用文字识别

调用的接口是:基于C++HTTP 的API

参数设置情况:none

开发平台和机型:LINUX ubuntu14.04

SDK版本号:none

代码或日志截图(上传截图能帮助您更快解决问题):

复现步骤、现象及其他描述:

按照官方的参考选择了curl用做HTTPS的请求,代码完全参考了官方提供的例程在图片base64编码内容长度小于1024(猜测),返回结果正常。

如图:

{"log_id": 3540079175, "words_result_num": 1, "words_result": [{"location": {"width": 12, "top": 9, "height": 15, "left": 7}, "words": "8"}]}

但是图片稍微大点(1280*720)就不行了,一直认为图片格式错误:

{"log_id": 192482879, "error_code": 216201, "error_msg": "image format error"}


请问服务器是否对post的请求长度的限制实际上未达到接口文档写了4M


curl开启日志后如图:

(正常)

* Hostname was NOT found in DNS cache

*   Trying 180.97.33.131...

* Connected to aip.baidubce.com (180.97.33.131) port 443 (#1)

* successfully set certificate verify locations:

*   CAfile: none

  CApath: /etc/ssl/certs

* SSL connection using ECDHE-RSA-AES128-GCM-SHA256

* Server certificate:

* subject: CN=aip.baidubce.com

* start date: 2017-01-03 00:00:00 GMT

* expire date: 2018-01-03 23:59:59 GMT

* subjectAltName: aip.baidubce.com matched

* issuer: C=CN; O=TrustAsia Technologies, Inc.; OU=Symantec Trust Network; OU=Domain Validated SSL; CN=TrustAsia DV SSL CA - G5

* SSL certificate verify ok.

> POST /rest/2.0/ocr/v1/general?access_token=(人为删除) HTTP/1.1

Host: aip.baidubce.com

Accept: */*

Content-Length: 696(BASE64编码的内容长度)

Content-Type: multipart/form-data; boundary=------------------------afb3de091f5a2e7e


< HTTP/1.1 200 OK

< Appid: 9649372

< Connection: keep-alive

< Content-Type: application/json

< Date: Tue, 23 May 2017 03:59:00 GMT

< P3p: CP=" OTI DSP COR IVA OUR IND COM "

< P3p: CP=" OTI DSP COR IVA OUR IND COM "

* Server Apache is not blacklisted

< Server: Apache

< Set-Cookie: BAIDUID=B48DBF31C97DCCD6D8D75F0C0252AC9A:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2145916555; path=/; domain=.baidu.com; version=1

< Set-Cookie: BAIDUID=8F751CFD64738A5C90B7F6C2CFF6C877:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2145916555; path=/; domain=.baidu.com; version=1

< Vary: Accept-Encoding

< Vary: Accept-Encoding

< Content-Length: 141

* Connection #1 to host aip.baidubce.com left intact

Baidu api ocr successful,json is{"log_id": 3540079175, "words_result_num": 1, "words_result": [{"location": {"width": 12, "top": 9, "height": 15, "left": 7}, "words": "8"}]}


(异常)

* Hostname was NOT found in DNS cache

*   Trying 180.97.33.131...

* Connected to aip.baidubce.com (180.97.33.131) port 443 (#1)

* successfully set certificate verify locations:

*   CAfile: none

  CApath: /etc/ssl/certs

* SSL connection using ECDHE-RSA-AES128-GCM-SHA256

* Server certificate:

* subject: CN=aip.baidubce.com

* start date: 2017-01-03 00:00:00 GMT

* expire date: 2018-01-03 23:59:59 GMT

* subjectAltName: aip.baidubce.com matched

* issuer: C=CN; O=TrustAsia Technologies, Inc.; OU=Symantec Trust Network; OU=Domain Validated SSL; CN=TrustAsia DV SSL CA - G5

* SSL certificate verify ok.

> POST /rest/2.0/ocr/v1/general?access_token=(人为删除) HTTP/1.1

Host: aip.baidubce.com

Accept: */*

Content-Length: 81276(BASE64编码后的内容长度)

Content-Type: multipart/form-data; boundary=------------------------90c54ef30b4366a1


< HTTP/1.1 200 OK

< Appid: 9649372

< Connection: keep-alive

< Content-Type: application/json

< Date: Tue, 23 May 2017 03:59:59 GMT

< P3p: CP=" OTI DSP COR IVA OUR IND COM "

< P3p: CP=" OTI DSP COR IVA OUR IND COM "

* Server Apache is not blacklisted

< Server: Apache

< Set-Cookie: BAIDUID=692C3A08312DCB3070E185997C1271A8:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2145916555; path=/; domain=.baidu.com; version=1

< Set-Cookie: BAIDUID=0155E4E87AE911E4FD5997158A620D15:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2145916555; path=/; domain=.baidu.com; version=1

< Vary: Accept-Encoding

< Vary: Accept-Encoding

< Content-Length: 78

* Connection #1 to host aip.baidubce.com left intact

Baidu api ocr successful,json is{"log_id": 192482879, "error_code": 216201, "error_msg": "image format error"}


收藏
点赞
0
个赞
共3条回复 最后由用户已被禁言回复于2022-04
#4goJhou回复于2017-12

是因为你们的图片二进制流 超过了post的字节大小限制

0
#3独孤焰坤回复于2017-12

怎么解决的啊,我做百度人脸的时候也一直是这个错误返回~

0
#2xie_yongkang回复于2017-05

您好, 语音识别的rest api支持的是语音文件的音频到文字的识别, 不支持图片。对于图片ocr接口的使用问题, 请至百度AI的官网http://ai.baidu.com 反馈, 谢谢。

0
TOP
切换版块