问题描述:

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())
相关阅读:
Top