繁体   English   中英

用ruby编写Avro并用Python阅读

[英]Write Avro in ruby and read in Python

我在尝试将用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)

谢谢。

通过这种方式修改代码可以解决问题

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM