类型错误:类型 'NoneType' 的参数在气流身份验证上不可迭代



我正在尝试在烧瓶中为气流实现OIDC身份验证:

FULL_NAME_OIDC_FIELD = 'name'
EMAIL_FIELD = 'email'
class AuthOIDCView(AuthOIDView):
@expose('/login/', methods=['GET', 'POST'])
def login(self, flag=True):
sm = self.appbuilder.sm
oidc = sm.oid
@self.appbuilder.sm.oid.require_login
def handle_login():
user = sm.auth_user_oid(oidc.user_getfield(EMAIL_FIELD))
if user is None:
info = oidc.user_getinfo(['last_name', 'email', 'role'])
full_name = info.get(FULL_NAME_OIDC_FIELD)
if " " in full_name:
full_name = full_name.split(" ")
last_name = full_name[1]
else:
last_name = ""
user = sm.add_user(
last_name=last_name,
email=info.get(EMAIL_FIELD),
role=sm.find_role('Admin')
)
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
return handle_login()

但是由于这个错误一直在失败

File "/opt/airflow/webserver_config.py", line 39, in handle_login
if " " in full_name:
TypeError: argument of type 'NoneType' is not iterable

我的理解是,user从OIDC服务器返回为空,但当我们尝试对其进行迭代时,它失败了,因为None是不可迭代的,这是正确的吗?

info.get(FULL_NAME_OIDC_FIELD)调用返回None对象。你需要先检查它是否真的是一个字符串。

相关内容

最新更新