It is not indicated which module is used to access Oracle, so I assume it is cx_Oracle.
When the LOB is read from Oracle, the OCI provides a LOB locator that is wrapped in a cx_Oracle object. Thus, in the example, dataDB [0] is not a string, but a cx_Oracle.LOB object. Depending on how ParseFromString is encoded, it may or may not be properly converted to a string.
Therefore, I would use dataDB [0] .read () as a parameter for ParseFromString.
cursor.execute("select myblob from mytable") for dataDB in cursor: lob = dataDB[0].read() print "size:", len(lob) mydata = Data_pb2.MyData() mydata.ParseFromString(lob)
In addition, the ByteSize () method is usually used during serialization to calculate the size of a serialized message. I'm not sure that it can be used immediately after parsing the message. In the protocol buffer API, ByteSize () is explicitly associated with serialization. In fact, it makes no sense to call it during parsing, since the size of the buffer is already known before parsing.
source share