What am I doing wrong here?
Python 3.6.5 (default, Apr 19 2018, 09:00:40)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from avro.schema import Parse as parse
>>> from avro import io
>>> schema = parse('"float"')
>>> from io import StringIO
>>> sio = StringIO()
>>> binenc = io.BinaryEncoder(sio)
>>> datwri = io.DatumWriter(schema)
>>> datwri.write(1.2, binenc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 811, in write
self.write_data(self.writer_schema, datum, encoder)
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 826, in write_data
encoder.write_float(datum)
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 358, in write_float
self.WriteByte((bits) & 0xFF)
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 319, in WriteByte
self.writer.write(bytes((byte,)))
TypeError: string argument expected, got 'bytes'
>>> datwri.write('1.2', binenc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 809, in write
raise AvroTypeException(self.writer_schema, datum)
avro.io.AvroTypeException: The datum 1.2 is not an example of the schema
"float"
>>> datwri.write('"1.2"', binenc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/michaels/.virtualenvs/tmp-c44183e906691bd/lib/python3.6/site-packages/avro/io.py",
line 809, in write
raise AvroTypeException(self.writer_schema, datum)
avro.io.AvroTypeException: The datum "1.2" is not an example of the schema
"float"
I can't encode 1.2 using a primitive float schema. What am I doing wrong?