Fixes AttributeError in Python3.

Not 100% sure if this is the correct solution as it might break in
Python 2 under certain conditions.