How Are you? I am play, with Python + Flask + MySQL to create a API. But I have some errors! With the connection. Here is the code of the Entry Point.
@app.route('/add', methods=['POST'])
def add_user():
try:
_json = request.json
_name = _json['name']
_email = _json['email']
_password = _json['pwd']
# validate the received values
if _name and _email and _password and request.method == 'POST':
#do not save password as a plain text
_hashed_password = generate_password_hash(_password)
# save edits
sql = "INSERT INTO user(user_name, user_email, user_password) VALUES(%s, %s, %s)"
data = (_name, _email, _hashed_password,)
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute(sql, data)
conn.commit()
resp = jsonify('User added successfully!')
resp.status_code = 200
return resp
else:
return not_found()
except Exception as e:
print(e)
finally:
cursor.close()
conn.close()
And here the error
I'm installed all the dependencies, but...I dont know. I connected the cursor, previosly, but nothing.
Can you help me? Thanks!


