AttributeError: 'str' object has no attribute 'decode' while reading from AVRO using Python
AttributeError: 'str' object has no attribute 'decode' while reading from AVRO using Python
from avro import io, datafile
import pprint
OUTFILE_NAME = "demo.avro"
rec_reader = io.DatumReader()
df_reader = datafile.DataFileReader(open(OUTFILE_NAME, 'r'), rec_reader)
pp = pprint.PrettyPrinter()
for record in df_reader:
pp.pprint(record)
df_reader.close()
我遇到了这个错误
"AttributeError: 'str' object has no attribute 'decode'".
如果有人能指导我什么是错误的,
提前致谢。
在Python3中,常规字符串是unicode
,没有decode
方法。字节串可以。
我对avro
一无所知,你也不显示错误堆栈。但可以很好地猜测 datafile.DataFileReader
需要一个以 rb
模式打开的文件。或者它可能采用文件名,open
本身(numpy
读者接受文件名或打开的文件)。
from avro import io, datafile
import pprint
OUTFILE_NAME = "demo.avro"
rec_reader = io.DatumReader()
df_reader = datafile.DataFileReader(open(OUTFILE_NAME, 'r'), rec_reader)
pp = pprint.PrettyPrinter()
for record in df_reader:
pp.pprint(record)
df_reader.close()
我遇到了这个错误
"AttributeError: 'str' object has no attribute 'decode'".
如果有人能指导我什么是错误的, 提前致谢。
在Python3中,常规字符串是unicode
,没有decode
方法。字节串可以。
我对avro
一无所知,你也不显示错误堆栈。但可以很好地猜测 datafile.DataFileReader
需要一个以 rb
模式打开的文件。或者它可能采用文件名,open
本身(numpy
读者接受文件名或打开的文件)。