Read jpeg file in Python, encode it into Unicode and put it into protobuf -


i transferring image python backend c++ backend. chose google protobuf, following simple structure:

message data {   optional string image = 1; } 

i use python read image , put image field:

data = server_pb2.data() data.image = (open(image_fn).read()) 

but protobuf complains following message:

value error: [hex data] has type str, isn't in 7-bit ascii encoding. non-ascii strings must converted unicode objects before being added.

i have tried several ways make data unicode without success.

maybe has encountered problem before? or there better way transfer image data?

thanks!

you should using bytes type in .proto file rather string.

bytes used arbitrary sequence of bytes (eg image). string used sequence of utf-8 or ascii characters (eg text).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -