I am working on a user register and login API. DB is MySQL. getAllUser is getting Properly. But when i am trying for post method for Inserting a row it's keep throwing this Error.
TypeError: not all arguments converted during string formatting
MY CODE: DB structure:
id(autoincrement), usr_name(varchar 30), password(varchar 20)
CODE for inserting :
As I am getting all user list perfectly the connections are correct.
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
Please help.. I really need this .. or any tutorial to follow on.