[英]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 这是我的代码,我想知道如何处理此错误,此错误来自第2行
you can use pythons try/except pair. 您可以使用python try / except对。
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. 这仅捕获AttributeError异常,因此仍然会引发其他任何情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.