AttributeError: 'NoneType' object has no attribute 'userName'
题
reqUser = friends.UserFriends.gql("where udid =:1", str(udid) ).get()
reqUserName = reqUser.userName
This is my code i want to know how to handle this error, this error comes at line 2
解决方案
you can use pythons try/except pair.
reqUser = friends.UserFriends.gql("where udid =:1", str(udid) ).get()
try:
reqUserName = reqUser.userName
except AttributeError:
reqUserName = "No username found!"
this catches only AttributeError exceptions, so anything else will still be raised.
不隶属于 StackOverflow