我想調用類的init函數中的類方法。我將一個字符串傳遞給函數,但錯誤顯示它是一個無類型的對象。AttributeError:'NoneType'對象沒有屬性'lower'
class UserSettings(object):
"""Value object representing a user's settings."""
def __init__(
self, user_id, email, username=None):
self.user_id = user_id
self.email = email
self.profile_picture_data_url = self.fetch_gravatar(email)
@classmethod
def fetch_gravatar(cls, email):
base_url = "http://www.gravatar.com/avatar/"
avatar_url = base_url + hashlib.md5(email.lower()).hexdigest() + "?"
avatar_url += urllib.urlencode({'d':'retro', 's':str(AVATAR_SIZE)})
return avatar_url
這裏的錯誤:
Traceback (most recent call last):
File "/home/travis/build/oppia/oppia/core/domain/user_services_test.py", line 78, in test_invalid_emails
user_services.get_or_create_user('user_id', email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 297, in get_or_create_user
user_settings = _create_user(user_id, email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 284, in _create_user
preferred_language_codes=[feconf.DEFAULT_LANGUAGE_CODE])
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 55, in __init__
self.profile_picture_data_url = self.fetch_gravatar(email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 129, in fetch_gravatar
avatar_url = base_url + hashlib.md5(email.lower()).hexdigest() + "?"
AttributeError: 'NoneType' object has no attribute 'lower'
請問您可以添加完整的錯誤輸出和fetch_gravatar調用嗎? – Altoyyr
'self.email.lower()'也許?不知道你在哪裏調用'fetch_gravatar',所以我們只能猜測。 – Lafexlos
@Lafexlos:無論如何,電子郵件正在傳遞給函數 –