AttributeError: 'list' object has no attribute 'endswith'