I am unsure why this code is giving me a 500 error on my web app with Flask, can someone tell me where my logic is wrong? I have a feeling it has to do with the sha256_crypt.verify() functions, but unsure how to get around this. Just trying to pull all the data on a user from my tables and put it into the session variable. Let me know, thanks!
@app.route('/login/', methods=['GET','POST'])
def login_page():
error = ''
try:
c, conn = connection()
if request.method == "POST":
c.execute("SELECT * FROM clients WHERE email = (%s)", (thwart(request.form['email']),))
pdata = c.fetchone()[3]
if sha256_crypt.verify(request.form['password'], pdata):
#get info from clients table
c.execute("SELECT * FROM clients WHERE email = (%s)", (email,))
clients_results = fetchall()
clientcid = clients_results[0]
#get info from cpersonals table
c.execute("SELECT * FROM cpersonals WHERE cid = (%s)", (clientcid,))
cpersonals_results = fetchall()
conn.commit()
c.close()
conn.close()
session['logged_in'] = 'client'
session['clientcid'] = clientcid
session['email'] = email
session['phone'] = clients_results[1]
session['rating'] = clients_results[4]
session['first_name'] = cpersonals_results[1]
session['last_name'] = cpersonals_results[2]
session['address'] = cpersonals_results[3]
session['czip'] = cpersonals_results[4]
session['reg_date'] = cpersonals_results[5]
flash("You are now logged in.")
return redirect(url_for("ask"))
else:
error = "Invalid credentials, try again."
return render_template("login.html", error = error)
except Exception as e:
#flash(e)
error = "Invalid credentials, try again."
return render_template("login.html", error = error)
Log: (sorry not sure how to post this properly)
.991239 mod_wsgi (pid=5585): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/view_unanswered/
.948625 mod_wsgi (pid=5585): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/view_unanswered/
.948649 Traceback (most recent call last):, referer: http://138.197.210.172/view_unanswered/
.948670 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/view_unanswered/
.948744 from FlaskApp import app as application, referer: http://138.197.210.172/view_unanswered/
.948857 File "/var/www/FlaskApp/FlaskApp/__init__.py", line 270, referer: http://138.197.210.172/view_unanswered/
.948869 conn.commit(), referer: http://138.197.210.172/view_unanswered/
.948873 ^, referer: http://138.197.210.172/view_unanswered/
.948877 IndentationError: unindent does not match any outer indentation level, referer: http://138.197.210.172/view_unanswered/
06.003866 mod_wsgi (pid=5586): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/account/
06.003919 mod_wsgi (pid=5586): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/account/
06.003942 Traceback (most recent call last):, referer: http://138.197.210.172/account/
06.003964 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/account/
06.004030 from FlaskApp import app as application, referer: http://138.197.210.172/account/
06.004076 File "/var/www/FlaskApp/FlaskApp/__init__.py", line 270, referer: http://138.197.210.172/account/
06.004083 conn.commit(), referer: http://138.197.210.172/account/
06.004087 ^, referer: http://138.197.210.172/account/
06.004090 IndentationError: unindent does not match any outer indentation level, referer: http://138.197.210.172/account/
09.513219 mod_wsgi (pid=5585): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/
09.513258 mod_wsgi (pid=5585): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/
09.513280 Traceback (most recent call last):, referer: http://138.197.210.172/
09.513301 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/
09.513335 from FlaskApp import app as application, referer: http://138.197.210.172/
09.513357 ImportError: cannot import name app, referer: http://138.197.210.172/
09.550576 mod_wsgi (pid=5586): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/view_unanswered/
09.550615 mod_wsgi (pid=5586): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/view_unanswered/
09.550639 Traceback (most recent call last):, referer: http://138.197.210.172/view_unanswered/
09.550661 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/view_unanswered/
09.550697 from FlaskApp import app as application, referer: http://138.197.210.172/view_unanswered/
09.550718 ImportError: cannot import name app, referer: http://138.197.210.172/view_unanswered/
12.922623 mod_wsgi (pid=5585): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/
12.922697 mod_wsgi (pid=5585): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/
12.922743 Traceback (most recent call last):, referer: http://138.197.210.172/
12.922768 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/
12.922807 from FlaskApp import app as application, referer: http://138.197.210.172/
12.922838 ImportError: cannot import name app, referer: http://138.197.210.172/
12.955475 mod_wsgi (pid=5586): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/
12.955537 mod_wsgi (pid=5586): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/
12.955561 Traceback (most recent call last):, referer: http://138.197.210.172/
12.955584 File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/
12.955620 from FlaskApp import app as application, referer: http://138.197.210.172/
12.955641 ImportError: cannot import name app, referer: http://138.197.210.172/
I fixed this awhile back and wanted to update the post in case anyone else runs into this.
So all I did was take the c.execute()
functions out of the sha256_crpt
IF statement, and put them at the beginning of the function for the page that login
redirects to. Every user visits the first page so the user session will always have these values.
As such :
@app.route('/ask/', methods=['GET','POST'])
def ask():
#clients come here first
error = ''
try:
c, conn = connection()
#grab all the clients info
email = session['email']
c.execute("SELECT cid FROM clients WHERE email = (%s)", (thwart(email),))
clientcid = c.fetchone()[0]
c.execute("SELECT phone FROM clients WHERE email = (%s)", (thwart(email),))
phone = c.fetchone()[0]
c.execute("SELECT rating FROM clients WHERE email = (%s)", (thwart(email),))
rating = c.fetchone()[0]
c.execute("SELECT first_name FROM cpersonals WHERE cid = (%s)", (clientcid,))
first_name = c.fetchone()[0]
c.execute("SELECT last_name FROM cpersonals WHERE cid = (%s)", (clientcid,))
last_name = c.fetchone()[0]
c.execute("SELECT address FROM cpersonals WHERE cid = (%s)", (clientcid,))
address = c.fetchone()[0]
c.execute("SELECT city FROM cpersonals WHERE cid = (%s)", (clientcid,))
city = c.fetchone()[0]
c.execute("SELECT state FROM cpersonals WHERE cid = (%s)", (clientcid,))
state = c.fetchone()[0]
c.execute("SELECT zip FROM cpersonals WHERE cid = (%s)", (clientcid,))
czip = c.fetchone()[0]
c.execute("SELECT reg_date FROM cpersonals WHERE cid = (%s)", (clientcid,))
reg_date = c.fetchone()[0]
conn.commit()
c.close()
conn.close()
session['logged_in'] = 'client'
session['clientcid'] = clientcid
session['phone'] = phone
session['rating'] = rating
session['first_name'] = first_name
session['last_name'] = last_name
session['address'] = address
session['city'] = city
session['state'] = state
session['czip'] = czip
session['reg_date'] = reg_date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.