尝试使用python将google视觉响应转换为字典时出现属性错误DESCRIPTOR [英] Attribute error DESCRIPTOR while trying to convert google vision response to dictionary with python
问题描述
我在 Windows 上,使用 Python 3.8.6rc1
、protobuf version 3.13.0
和 google-cloud-vision version 2.0.0
.
I am on Windows, using Python 3.8.6rc1
, protobuf version 3.13.0
and google-cloud-vision version 2.0.0
.
我的代码是:
from google.protobuf.json_format import MessageToDict
from google.cloud import vision
client = vision.ImageAnnotatorClient()
response = client.annotate_image({
'image': {'source': {'image_uri': 'https://images.unsplash.com/photo-1508138221679-760a23a2285b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'}},
})
MessageToDict(response)
它在 MessageToDict(response)
处失败,我有一个 属性错误:DESCRIPTOR"
.看起来 response
不是有效的 protobuf 对象.有人能帮我吗?谢谢
It fails at MessageToDict(response)
, I have an attribute error: "DESCRIPTOR"
. It seems like the response
is not a valid protobuf object. Can someone help me? Thank you
推荐答案
这并没有真正回答我的问题,但我发现解决它并访问 protobuf 对象的一种方法是使用 response._pb
所以代码变成:
This does not really answer my question but I find that one way to solve it and access the protobuf object is to use response._pb
so the code becomes:
response = client.annotate_image({
'image': {'source': {'image_uri': 'https://images.unsplash.com/photo-1508138221679-760a23a2285b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'}},
})
MessageToDict(response._pb)
这篇关于尝试使用python将google视觉响应转换为字典时出现属性错误DESCRIPTOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!