Fix TypeError in Python 3