The module 'avro.schema' does not have the attribute 'parse'

I am new to python and I was trying to write simple code to convert a text file to avro. I get this error that the module was not found. I could clearly see in the schema.py file that the parser exists. I would appreciate it if someone would help me understand what I might be doing wrong.

import avro.schema, csv, codecs from avro.datafile import DataFileReader, DataFileWriter from avro.io import DatumReader, DatumWriter def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs): # csv.py doesn't do Unicode; encode temporarily as UTF-8: csv_reader = csv.reader(utf_8_encoder(unicode_csv_data), dialect=dialect, **kwargs) for row in csv_reader: # decode UTF-8 back to Unicode, cell by cell: yield [unicode(cell, 'utf-8') for cell in row] def utf_8_encoder(unicode_csv_data): for line in unicode_csv_data: yield line.encode('utf-8') schema = avro.schema.parse(open('C:/test/test.avsc', "rb").read()) 

I am using Python 3.5.2, avro-python3-1.8.1 on Windows 10.

+5
source share
1 answer

You have sample avro code from the tutorial , but unfortunately it is not updated for avro-python3 .

Instead:

 schema = avro.schema.parse(open('file.avsc', "rb").read()) 

You need to read the file in text mode and use the Parse() method:

 schema = avro.schema.Parse(open('file.avsc', "r").read()) 
+10
source

Source: https://habr.com/ru/post/1262112/


All Articles