TypeError:在字符串格式化python Flask期间不是所有参数都被转换

时间:2018-03-03 06:13:02

标签: python mysql api flask sql-insert

我正在开发用户注册和登录API。 DB是MySQL。 getAllUser越来越正常了。但是,当我尝试插入行的post方法时,它会继续抛出此错误。

TypeError: not all arguments converted during string formatting

我的代码:数据库结构:

 id(autoincrement), usr_name(varchar 30), password(varchar 20)

用于插入的代码:

当我完全获得所有用户列表时,连接是正确的。

mysql = MySQL()

app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'xxx'
app.config['MYSQL_DATABASE_PASSWORD'] = 'xxx'
app.config['MYSQL_DATABASE_DB'] = 'xxx'
app.config['MYSQL_DATABASE_HOST'] = 'xxx.xxx.xxx.xxx'

mysql.init_app(app)


class UserRegister(Resource):
    TABLE_NAME = 'user'

    parser = reqparse.RequestParser()
    parser.add_argument('usr_name',
        required=True,
        help="This field cannot be left blank!"
    )
    parser.add_argument('password',
        required=True,
        help="This field cannot be left blank!"
    )


    def post(self):
        data = UserRegister.parser.parse_args()
        print(data)
        cursor = mysql.connect().cursor()

        query = "INSERT INTO {table} VALUES (NULL, ?, ?)".format(table=self.TABLE_NAME)
        cursor.execute(query, (data['usr_name'], data['password']))

        return {"message": "User created successfully."}, 201

请帮助..我真的需要这个..或任何教程可以继续。

1 个答案:

答案 0 :(得分:0)

错误已解决

int range = 5; //the range of integers you want to match the level (in this case it will be from 0 to 4)

int signalStrength = WifiManager.calculateSignalLevel(rssi, range);