简体   繁体   English

得到错误 TypeError: execute() 没有关键字 arguments

[英]Got the error TypeError: execute() takes no keyword arguments

I am trying to build a register/login system with python and sqlite3.我正在尝试使用 python 和 sqlite3 构建一个注册/登录系统。 It seems to be there is something wrong here in my code.我的代码似乎有问题。

        if request.form.get("password") != request.form.get("confirm"):
            return apology(" Passwords doesn't match")

#       try:

        prim_key = c.execute("INSERT INTO accounts (username, hash) VALUES (:username, :hash)",
                                 username = request.form.get("username"),
                                 hash = generate_password_hash(request.form.get("password")))
        conn.commit()

#       except:
#           return apology("Sorry! username already exists!", 403)
#       if prim_key is None:
#           return apology("Failed to register! something went wrong!", 403)
#       user_if = prim_key
        return redirect("/")
    else:
        return render_template("register.html")

I commented some lines to figure out if what is wrong.我评论了一些行,以确定是否有问题。 Before quoting I kept getting the error "Sorry. username already exists!".在引用之前,我不断收到错误“对不起。用户名已经存在!”。

Now after quoting those lines when I run the application I get现在,在我运行应用程序时引用这些行后,我得到了

File "application.py", line 76, in register prim_key = c.execute("INSERT INTO accounts (username, hash) VALUES (:username, :hash)", TypeError: execute() takes no keyword arguments文件“application.py”,第 76 行,寄存器 prim_key = c.execute("INSERT INTO accounts (username, hash) VALUES (:username, :hash)", TypeError: execute() 没有关键字 arguments

I wonder if I am missing, something these are the modules I imported.我想知道我是否遗漏了这些是我导入的模块。

import sqlite3
from flask import Flask, flash, jsonify, redirect, render_template, request, session
from werkzeug.security import check_password_hash, generate_password_hash
import secrets

And if I can't use keyword arguments here, is there a way around this?如果我不能在这里使用关键字 arguments,有没有办法解决这个问题? Or am I doing the entire thing wrong?还是我做错了整个事情? I am new to Python so I don't know if this is just a dumb question.我是 Python 的新手,所以我不知道这是否只是一个愚蠢的问题。 I read almost all the questions like this one, but I couldn't figure any way to get this done.我几乎阅读了所有类似这样的问题,但我想不出任何办法来完成这项工作。 So any help is appreciated.所以任何帮助表示赞赏。 Thank you for your time!感谢您的时间!

As the error states, execute doesn't take any keyword arguments.如错误所示, execute不使用任何关键字 arguments。 You need to just pass a dict of values instead:您只需要传递一个值的字典:

prim_key = c.execute("INSERT INTO accounts (username, hash) VALUES (:username, :hash)",
                     { 'username': request.form.get("username"), 
                       'hash': generate_password_hash(request.form.get("password"))
                     })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM