我在Windows上,使用Python 3.8.6rc1
、protobuf version 3.13.0
和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)
失败,我有一个attribute error: "DESCRIPTOR"
。看起来response
不是有效的protobuf对象。有人能帮我吗?多谢各位
这并没有真正回答我的问题,但我发现解决它并访问protobuf对象的一种方法是使用
response._pb
,因此代码变成:看第三步
步骤1:导入此库
步骤2:发送请求
步骤3:将响应转换为json[Look here]
第四步:用这个
做任何你想做的事json
同一问题的Github:here
也许看看this post
相关问题 更多 >
编程相关推荐