Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

How to serialize SqlAlchemy result to JSON?