AttributeError: 'str' object has no attribute 'encoding'