尝试将python的Google视觉响应转换为字典时出现属性错误DESCRIPTOR [英] Attribute error DESCRIPTOR while trying to convert google vision response to dictionary with python
本文介绍了尝试将python的Google视觉响应转换为字典时出现属性错误DESCRIPTOR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows上,使用 Python 3.8.6rc1
, protobuf版本3.13.0
和 google-cloud-vision版本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屋!
查看全文