Fixed TypeError in Python 3.

Fix for astropy/astropy#2821