因此,工作和不工作的区别在于在MySQLdb的SELECT address execute()语句下面插入SELECT语句。你知道吗
我的功能:
@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 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['czip'] = czip
session['reg_date'] = reg_date
#if user posts a question to the pool
if request.method == 'POST':
#grab question info from form
difficulty = request.form['difficulty']
title = request.form['title']
body = request.form['body']
clientcid = session['clientcid']
c, conn = connection()
c.execute("INSERT INTO tickets (cid, difficulty, title, body) VALUES (%s, %s, %s, %s)", (clientcid, difficulty, thwart(title), thwart(body)))
conn.commit()
c.close()
conn.close()
flash("Submission successful.")
return redirect(url_for('ask'))
else:
error = "We couldn't post your question, please reload the page and try again!"
return render_template("ask.html")
except Exception as e:
return(str(e))
在SELECT address FROM cpersonals
下方插入此命令:
c.execute("SELECT city FROM cpersonals WHERE cid = (%s)", (clientcid,))
city = c.fetchone()[0]
超级混乱,因为这与上面用于获取地址的SELECT语句相同,但会导致500错误。有人知道我可以从哪些方面来解决这个问题吗?为什么会这样?你知道吗
编辑: Apache错误日志:
[Tue Nov 14 03:20:26.932754 2017] [mpm_event:notice] [pid 10241:tid 140272413560320] AH00491: caught SIGTERM, shutting down
[Tue Nov 14 03:20:27.002887 2017] [mpm_event:notice] [pid 10347:tid 140399854022144] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.11 Python/2.7 configured -- resuming normal operations
[Tue Nov 14 03:20:27.003054 2017] [core:notice] [pid 10347:tid 140399854022144] AH00094: Command line: '/usr/sbin/apache2'
[Tue Nov 14 03:20:28.212299 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] mod_wsgi (pid=10351): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212379 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] mod_wsgi (pid=10351): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212415 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] Traceback (most recent call last):, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212451 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212558 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] from FlaskApp import app as application, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212622 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 41, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212635 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] c.execute("SELECT state FROM cpersonals WHERE cid = (%s)", (clientcid,)), referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212641 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] ^, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.212647 2017] [wsgi:error] [pid 10351:tid 140399645546240] [client 108.196.200.128:64860] SyntaxError: invalid syntax, referer: http://138.197.210.172/login/
[Tue Nov 14 03:20:28.269478 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] mod_wsgi (pid=10350): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269538 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] mod_wsgi (pid=10350): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269566 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] Traceback (most recent call last):, referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269594 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269679 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] from FlaskApp import app as application, referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269730 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 41, referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269740 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] c.execute("SELECT state FROM cpersonals WHERE cid = (%s)", (clientcid,)), referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269747 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] ^, referer: http://138.197.210.172/ask/
[Tue Nov 14 03:20:28.269753 2017] [wsgi:error] [pid 10350:tid 140399578404608] [client 108.196.200.128:64861] SyntaxError: invalid syntax, referer: http://138.197.210.172/ask/
弄明白了:我所需要做的就是在
try
语句下面的语句中添加tab。我想这是因为Python对tab非常挑剔!你知道吗例如:
相关问题 更多 >
编程相关推荐