I am trying to convert the response from Google Cloud Vision API Client Library to a json format. However i get the following error:
AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'DESCRIPTOR
Resource
from flask_restful import Resource
from flask import request
from flask import json
from util.GoogleVision import GoogleVision
from util.Convert import Convert
import base64
import requests
import os
class Vision(Resource):
def post(self):
googleVision = GoogleVision()
req = request.get_json()
url = req['url']
result = googleVision.detectLabels(url)
return result
GoogleVision.py
import os
from google.cloud import vision
from google.cloud.vision import types
from google.protobuf.json_format import MessageToJson
class GoogleVision():
def detectLabels(self, uri):
client = vision.ImageAnnotatorClient()
image = types.Image()
image.source.image_uri = uri
response = client.label_detection(image=image)
labels = response.label_annotations
res = MessageToJson(labels)
return res
the labels variable is of type <class'google.protobuf.pyext._message.RepeatedCompositeContainer'>
As you can see i am using message to json function on the labels response. But i am getting the above error.
Is there a way to convert the result to a json format?