-
Notifications
You must be signed in to change notification settings - Fork 84
Protobuf messages can no longer be deserialized after migration to 2.0.0 #64
Comments
Hi there, Are there any news on this topic? It's a blocking issue for my use case. I will not be able to use the new version until this is fixed. Thanks, Alex |
I've encountered the same issue. My config: I tried different permutations of library versions and this is what I found: has issue no issue Happy to run other tests as well if it helps get this issue resolved. Alex M |
Hi folks, The 2.0.0 uses messages provided by proto-plus, which wraps the raw protobuf messages. See this issue for examples of how to serialize and deserialize messages. |
For anyone who comes across this thread in the future or is still trying to figure how how to get this working, here is some code and notes. import io, json
from google.cloud import vision_v1
from google.cloud.vision_v1 import AnnotateImageResponse
with io.open('000048.jpg', 'rb') as image_file:
content = image_file.read()
image = vision_v1.Image(content=content)
client = vision_v1.ImageAnnotatorClient()
response = client.document_text_detection(image=image)
# serialize / deserialize proto (binary)
serialized_proto_plus = AnnotateImageResponse.serialize(response)
response = AnnotateImageResponse.deserialize(serialized_proto_plus)
print(response.full_text_annotation.text)
# serialize / deserialize json
response_json = AnnotateImageResponse.to_json(response)
response = json.loads(response_json)
print(response['fullTextAnnotation']['text']) Note 1: proto-plus doesn't support converting to snake_case names, which is supported in protobuf with "preserving_proto_field_name=True". So currently there is no way around the field names being converted from response['full_text_annotation'] to response['fullTextAnnotation'] Note 2: The google vision api doesn't return an x coordinate if x=0. If x doesn't exist, the protobuf will default x=0. In python vision 1.0.0 using MessageToJson(), these x values weren't included in the json, but now with python vision 2.0.0 and .To_Json() these values are included as x:0 |
Thanks @tubli @busunkim96. I managed to make it work with the following code snippet from @TobKed which does that for any protobuf message: googleapis/python-memcache#19 (comment) I think an update of the google-cloud-vision Python library documentation would really help others encountering the same issue. |
@tubli This response is spot on. We'll update the documentation to make it less opaque and frustrating to folks upgrading to client library versions that use proto plus. |
Environment details
google-cloud-vision
version: 2.0.0protobuf
version: 3.13.0Steps to reproduce
client.annotate_image(request)
=> SUCCESS (request is valid and you can print the output)Code example
Stack trace
I read other issues, and it seems this bug is linked to 2 other issues: #60 #58
The text was updated successfully, but these errors were encountered: