2016-10-08 63 views
0

我在 https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html谷歌视觉API错误代码

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。我错过了什么?

+0

我与domain.com/x.jpg有同样的问题,这是因为有一个.htaccess规则将domain.com/x.jpg.jpg转发到www.domain.com/xyz.jpg。用www发送图片网址。解决了这个问题。 –

回答

0

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

你可能试着重新编码你的图像吗?将它保存为PNG或重新保存为JPG,看看它可能是损坏的或任何东西?

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'