Fixed segfault on invalid unicode char on python 3

Fix for #138. 

And made the tests work for Python 3 to be able to add a test for this fix.