我有这种方法来检查所连接的用户是否是谷歌应用程序域的管理员:
user = users.get_current_user()
if user and check_email(user):
print 'user is a domain admin'
else:
print 'user is not a domain admin'
def check_email(user):
domain = urlparse(user.federated_identity()).hostname
m = re.search('.*@' + domain, user.email())
if m:
return True
else:
return False
在app引擎服务器上部署后,我得到错误500,我已经验证了日志并获得了此跟踪跟踪:
'NoneType' object has no attribute 'find'
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~apps/1.374581528892117369/handler.py", line 21, in get
if user and check_email(user):
File "/base/data/home/apps/s~apps/1.374581528892117369/utils/utils.py", line 18, in check_email
domain = urlparse(user.federated_identity()).hostname
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urlparse.py", line 142, in urlparse
tuple = urlsplit(url, scheme, allow_fragments)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urlparse.py", line 181, in urlsplit
i = url.find(':')
AttributeError: 'NoneType' object has no attribute 'find'
我关注this structures并没有找到问题! 任何根本原因的想法?
答案 0 :(得分:0)
您看到此错误是因为您尝试使用None调用urlparse()。 像下面这样的东西可以解决你的问题。
def check_email(user):
if user.federated_identity() is not None:
domain = urlparse(user.federated_identity()).hostname
m = re.search('.*@' + domain, user.email())
if m:
return True
else:
return False