在Python中读取Avro文件时出错

时间:2018-04-30 19:04:23

标签: python python-3.x avro

我试图将一个avro文件读入Python,以下代码适用于OSX和Linux机箱但在Windows上中断:

from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter

reader = DataFileReader(open("my_file.avro", "rb"), DatumReader())
for line in reader:
    print(line)
    break

为什么我只在Windows上出现以下错误?

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Program Files\Python36\lib\site-packages\avro\datafile.py", line 351, in __init__
    self._read_header()
  File "C:\Program Files\Python36\lib\site-packages\avro\datafile.py", line 463, in _read_header
    META_SCHEMA, META_SCHEMA, self.raw_decoder)
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 526, in read_data
    return self.read_record(writer_schema, reader_schema, decoder)
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 726, in read_record
    field_val = self.read_data(field.type, readers_field.type, decoder)
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 522, in read_data
    return self.read_map(writer_schema, reader_schema, decoder)
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 657, in read_map
    key = decoder.read_utf8()
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 249, in read_utf8
    input_bytes = self.read_bytes()
  File "C:\Program Files\Python36\lib\site-packages\avro\io.py", line 241, in read_bytes
    assert (nbytes >= 0), nbytes
AssertionError: -51

在Windows上使用avro-tools-1.8.2.jar时出现以下错误(在mac上使用avro-tools-1.8.2.jar):

PS D:\Temp> java -jar avro-tools-1.8.2.jar tojson my_file.avro
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.io.IOException: Not a data file.
        at org.apache.avro.file.DataFileStream.initialize(DataFileStream.java:105)
        at org.apache.avro.file.DataFileStream.<init>(DataFileStream.java:84)
        at org.apache.avro.tool.DataFileReadTool.run(DataFileReadTool.java:71)
        at org.apache.avro.tool.Main.run(Main.java:87)
        at org.apache.avro.tool.Main.main(Main.java:76)

0 个答案:

没有答案