Dave DeCaprio
Dave DeCaprio

Reputation: 2101

Python Avro on windows gives ord() expected a character, but string of length 0 found

I am attempting to write an Avro serialization file using Java and then read it in using Python on windows. I am able to write out the Avro file using Java, but when I attempt to read it in using Python I get an error "ord() expected a character, but string of length 0 found"

It is not an error with the file being incomplete or not flushed, since I can read the file in through Java completely and it reads in fine.

It is not a basic error with my python setup since I can run the sample serialization/deserialization on the Avro Getting Started page: http://avro.apache.org/docs/current/gettingstartedpython.html

Any ideas what this could be.

Upvotes: 3

Views: 1531

Answers (1)

Dave DeCaprio
Dave DeCaprio

Reputation: 2101

I'm answering this myself since I saw several similar posts on various forms and none of them were answered.

The problem was that I was opening my python file using mode "r" instead of "rb". This reads in fine until it hits a byte with hex 0x1A, which gets interpreted as end of file on windows. The solution is to open the file as binary.

(I'd suggest that the Avro getting started (Python) page change to using binary mode files to avoid other people running into this.)

Upvotes: 5

Related Questions