【问题标题】:sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type boolean: "sdzf"sqlalchemy.exc.DataError:(psycopg2.errors.InvalidTextRepresentation)布尔类型的无效输入语法:“sdzf”
【发布时间】:2021-04-14 08:28:23
【问题描述】:

我正在我的电子商务网站中创建一个更新用户凭据的功能。每当我的表单触发此函数时,我都会收到错误-> sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) 布尔类型的无效输入语法:“sdzf”

我无法找出问题所在。请帮我找出问题。提前致谢。

python 代码:

@app.route("/admin_cred_update", methods=["POST","GET"])
def admin_cred_update():
    email=str(request.form.get("email"))
    password=str(request.form.get("password"))
    if re.search("[.,*/%$#:|\[\]\(\)]",email) and re.search("[.,*/%$#:|\[\]\(\)]",password):
        message="there are some invalid characters in above fields"
        return render_template("admin_profile.html", updatemes=message)
    else:
        db.execute("update admin_master_tbl SET email=:email and password=:password where email=:smail and password=:spassword",{"email":email,"password":password,"smail":session["adminname"],"spassword":session["adminpassword"]})
        session["adminname"]=email
        session["adminpassword"]=password
        message1="credentials updated succesfully"
        return render_template("admin_profile.html", updatemes=message1)

错误日志:

sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid   input syntax for type boolean: "sdzf"
LINE 1: update admin_master_tbl SET email='sdzf' and password='csadf...
                                          ^

[SQL: update admin_master_tbl SET email=%(email)s and password=%(password)s  where email=%(smail)s and password=%(spassword)s]
[parameters: {'email': 'sdzf', 'password': 'csadfc', 'smail': 'lightningdrago72@gmail.com', 'spassword': 'asdf'}]

【问题讨论】:

  • 阅读 psycopg2 文档了解如何使用参数,Parameters
  • 嗨@AdrianKlaver,我看到了文档并尝试使用不同的方法,但我仍然得到同样的错误。请再次检查我的代码和错误我做了一些更改。
  • admin_master 的架构定义是什么?它看起来像 email 字段是 boolean 类型,您正在尝试在其中输入字符串值。
  • 不是@AdrianKlaver,email 字段是varchar 类型。

标签: python-3.x postgresql flask flask-sqlalchemy


【解决方案1】:

哦,我发现了问题!我错误地将and 而不是, 放在我的查询的SET 部分。现在问题解决了!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多