Fix crash in python 3.
Merge pull request #2097 from nouiz/py3

Fix crash in python 3.