Ich habe versucht, mich auf der Seite zu registrieren, die ich entwickelt habe. Du findest deinen Code hier auf GitHub. Es besteht aus einigen SQL-Anfragen in der POST-Methode für eine PostgreSQL-Datenbank.
psycopg2.InternalError: current transaction is aborted,
commands ignored until end of transaction block
Hier ist der Code in [app.py] 2:
# User Register
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegisterForm(request.form)
if request.method == 'POST' and form.validate():
name = form.name.data
email = form.email.data
username = form.username.data
password = sha256_crypt.encrypt(str(form.password.data))
# Create cursor
cur = mysql.connection.cursor()
# Execute query
cur.execute("INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)", (name, email, username, password))
# Commit to DB
mysql.connection.commit()
# Close connection
cur.close()
flash('You are now registered and can log in', 'success')
return redirect(url_for('login'))
return render_template('register.html', form=form)
Hier ist der vollständige Fehler:
2018-07-02T17:14:35.231415+00:00 heroku[router]: at=info method=GET path="/register" host=rosenberg-moodbot.herokuapp.com request_id=1b86212b-13a9-45be-b6f6-99dd379af98e fwd="193.60.231.83" dyno=web.1 connect=0ms service=4ms status=200 bytes=2769 protocol=https
2018-07-02T17:14:55.966856+00:00 heroku[router]: at=info method=POST path="/register" host=rosenberg-moodbot.herokuapp.com request_id=c9894f61-1d09-4c45-ad08-1460af61b8dc fwd="193.60.231.83" dyno=web.1 connect=1ms service=661ms status=500 bytes=450 protocol=https
2018-07-02T17:14:55.967005+00:00 app[web.1]: [2018-07-02 17:14:55,966] ERROR in app: Exception on /register [POST]
2018-07-02T17:14:55.967013+00:00 app[web.1]: Traceback (most recent call last):
2018-07-02T17:14:55.967016+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
2018-07-02T17:14:55.967018+00:00 app[web.1]: response = self.full_dispatch_request()
2018-07-02T17:14:55.967021+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
2018-07-02T17:14:55.967023+00:00 app[web.1]: rv = self.handle_user_exception(e)
2018-07-02T17:14:55.967025+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
2018-07-02T17:14:55.967026+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2018-07-02T17:14:55.967031+00:00 app[web.1]: raise value
2018-07-02T17:14:55.967028+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
2018-07-02T17:14:55.967032+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
2018-07-02T17:14:55.967034+00:00 app[web.1]: rv = self.dispatch_request()
2018-07-02T17:14:55.967036+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
2018-07-02T17:14:55.967038+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2018-07-02T17:14:55.967040+00:00 app[web.1]: File "app.py", line 111, in register
2018-07-02T17:14:55.967042+00:00 app[web.1]: cur.execute("INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)", (name, email, username, password))
2018-07-02T17:14:55.967044+00:00 app[web.1]: psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
2018-07-02T17:14:55.967053+00:00 app[web.1]:
2018-07-02T17:14:55.967477+00:00 app[web.1]: 10.123.227.73 - - [02/Jul/2018 17:14:55] "POST /register HTTP/1.1" 500 -
Weißt du, was ich an der Methode falsch gemacht habe?
Nach [ihrer FAQ] 3 I:
must run a
rollback()
before sending new commands to the session
Aber wie kann ich das tun? Sollte ich es dem Code hinzufügen? Woher ?