Fixed bug in State serialization in Python, where exception would occur.
Added test.