Google Vision API错误代码

时间:2016-10-08 16:19:53

标签: python google-cloud-vision google-cloud-python

我正在尝试使用示例代码 https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html

from google.cloud import vision
   client = vision.Client()
   image = client.image('./image.jpg')
   safe_search = image.detect_safe_search()

image.detect_safe_search会为api返回的结果抛出一个键错误。在打印结果字典时,我发现它没有预期的键,因为它给出了错误响应。谷歌api返回的响应是

{u'error': {u'message': u'image-annotator::error(12): Image processing error!', u'code': 13}}

我在api的文档中找不到任何关于错误代码的引用。我错过了什么?

2 个答案:

答案 0 :(得分:0)

Here's an issue也提到错误。该问题已转发给Google工程团队。

您是否可以尝试重新编码图片?将它保存为png或重新保存到jpg以查看它是否已损坏或其他任何内容?

答案 1 :(得分:0)

看来文档不正确。

此示例有效。

from google.cloud import vision

client = vision.Client()

with open('yourimage.jpg', 'rb') as file_obj:
    my_image = client.image(content=file_obj.read())
results = my_image.detect_safe_search()

print(results[0].medical)
# 'VERY_UNLIKELY'