当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Read Avro and parse from web

问题描述:

I used urllib2 to get an avro file into my variable "myavro".

How do I read it into the Python Avro library?

I have tried the following:

a = urllib2.urlopen(url)

myavro = a.read()

reader = DataFileReader(open(myavro, "r"), DatumReader())

网友答案:

It wants bytes not a str. Try:

from io import BytesIO
a = urllib2.urlopen(url)
myavro = a.read()
reader = DataFileReader(BytesIO(myavro), DatumReader())
分享给朋友:
您可能感兴趣的文章:
随机阅读: