Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x KeyError:';文本注释';在使用Google Cloud Vision API进行OCR时_Python 3.x_Google Cloud Platform_Ocr_Google Cloud Vision_Keyerror - Fatal编程技术网

Python 3.x KeyError:';文本注释';在使用Google Cloud Vision API进行OCR时

Python 3.x KeyError:';文本注释';在使用Google Cloud Vision API进行OCR时,python-3.x,google-cloud-platform,ocr,google-cloud-vision,keyerror,Python 3.x,Google Cloud Platform,Ocr,Google Cloud Vision,Keyerror,我正在学习OCR教程。我所做的一切都与教程中提到的一样,但是在上一部分生成请求时,我遇到了这个错误KeyError:'textAnnotations'。我能知道怎么解决这个问题吗?我的输入图像只是一个字符a 以下是我创建请求的方式: from googleapiclient.discovery import build import base64 IMAGE="gs://<project-name>/<folder>/<file-name>.jpg&

我正在学习OCR教程。我所做的一切都与教程中提到的一样,但是在上一部分生成请求时,我遇到了这个错误
KeyError:'textAnnotations'
。我能知道怎么解决这个问题吗?我的输入图像只是一个字符
a

以下是我创建请求的方式:

from googleapiclient.discovery import build
import base64
IMAGE="gs://<project-name>/<folder>/<file-name>.jpg"
vservice = build('vision', 'v1', developerKey=APIKEY)
request = vservice.images().annotate(body={
    'requests': [{
       'image': {
          'source': {
             'gcs_image_uri': IMAGE
          }
      },
      'features': [{
          'type': 'TEXT_DETECTION',
          'maxResults': 3,
        }]
     }],
  })
responses = request.execute(num_retries=3)
print(responses['responses'][0]['textAnnotations'][0]['description'])
来自GoogleAppClient.discovery导入生成的

导入base64
IMAGE=“gs://.jpg”
vservice=build('vision','v1',developerKey=APIKEY)
request=vservice.images().annotate(正文={
“请求”:[{
“图像”:{
“来源”:{
“gcs_图像_uri”:图像
}
},
“特征”:[{
“类型”:“文本检测”,
“maxResults”:3,
}]
}],
})
响应=请求。执行(重试次数=3)
打印(响应['responses'][0]['textAnnotations'][0]['description'])

API在出现错误时返回的响应结构不同于
响应['responses'][0]['textAnnotations'][0]['description']

我的意见是,这是一个错误,因此你的回答没有你认为它的形状。正如Caleb所建议的,我将打印完整的响应,并首先查看其中的内容

请添加响应和代码,此错误意味着他在响应中找不到“textAnnotations”。@Inga890我正在阅读我链接的教程。最后,他们正在创建一个请求。它的结果应该是图像中的文本,但我得到了关键错误。我在问题中添加了上述请求。关键错误来自打印。你得到答复了吗?你能附上它吗?你需要检查它是否在你的图像中检测到了字母。检查
响应['responses'][0]
的长度,或者将其作为一个整体打印出来,看看里面有什么。