I'm working with a google API to process documents from upload. What I'm trying to achieve is saving the protobuf in the response as a .proto
file so I could work with it later.
I can do response._pb.SerializeToString()
, however, I couldn't figure out how to work with this later. I tried to write this result in a .proto
format file like:
with open("doc.proto", "wb") as f:
f.write(response._pb.SerializeToString())
But the file does not seem like a proper .proto
file and I couldn't run it through the protoc compiler as follows:
protoc -I=. --python_out=. ./doc.proto
I get a bunch of errors like:
doc.proto:7398:6: Invalid control characters encountered in text.
doc.proto:7398:9: Interpreting non ascii codepoint 225.
doc.proto:7398:12: Invalid control characters encountered in text.
doc.proto:7398:15: Need space between number and identifier.
doc.proto:7398:16: Invalid control characters encountered in text.
To summarize, I'm just trying to serialize/deserialize the protobuf API response.