用红宝石写Avro并用Python阅读

时间:2016-07-20 19:22:15

标签: python ruby avro

我正面临着尝试将用Ruby编写的Avro字节解码为Kafka主题的问题。在观察avro字节字符串时我可以看到它看起来很好。但是当我尝试解码时,我得到一个'UnicodeDecodeError:'utf8'编解码器无法解码位置32的字节0x98:无效的起始字节'。

import avro.schema
import avro.io
import io

bytes_reader = io.BytesIO(m.value)
decoder = avro.io.BinaryDecoder(bytes_reader)
reader = avro.io.DatumReader(schema)
print reader.read(decoder)

感谢。

1 个答案:

答案 0 :(得分:0)

以这种方式修改代码解决了问题

bytes_reader = io.BytesIO(msg.value)
reader = DataFileReader(bytes_reader, DatumReader())
for r in reader:
    print r