[英]How can I solve : TypeError: 'NoneType' object is not iterable
I have a Python Flask code and here is this error for me: TypeError: 'NoneType' object is not iterable.我有一个 Python Flask 代码,这是我的错误:TypeError: 'NoneType' object is not iterable。 Thus, in the app there are two types of sessions: pro and common, if the user's email is in the db pro list it will be redirected to a screen, otherwise it will be redirected to it.
因此,在应用程序中有两种类型的会话:pro 和 common,如果用户的 email 在 db pro 列表中,它将被重定向到屏幕,否则将被重定向到它。
###########################
conn = mysql.connector.connect(host="localhost",
database="*********", user="root",
password="********")
ku = conn.cursor()
em = ku.execute("SELECT Email FROM pro WHERE email=%s",(emails,))
emm = ku.fetchone()
nms2 = [str(i) for i in emm]
emai = str("".join(nms2))
###########################
if resposta:
session["loggedin"] = True
session["email"] = resposta[1]
if emails in emai:
return redirect(url_for("home_pro"))
return redirect(url_for("home"))
else:
msg="Email/Senha incorretos"
###########################
How can I resolve this error?如何解决此错误? In Python, the error is on the line: nms2 = [str(i) for i in emm]
在Python中,报错就行了:nms2 = [str(i) for i in emm]
Check if the emm
is empty/None before running a for loop on it.在对其运行 for 循环之前检查
emm
是否为空/无。
fetchone()
method gives the row if required row exist in database.如果数据库中存在所需的行,则
fetchone()
方法给出该行。 there is no row in database where your condition is matched.数据库中没有与您的条件匹配的行。 You can handle this error like this:
您可以像这样处理此错误:
if emm is not None:
nms2 = [str(i) for i in emm]
emai = str("".join(nms2))
else:
print("No row found with that email")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.