我只是弄明白MySQLdb
也有conn.select_db()
功能。然后,我尝试将其与Flask
同时合并。
这是我的代码:
from flask import Flask
from flask import request
import MySQLdb
app = Flask(__name__)
@app.route("/home")
def hello():
return "Hello World"
# MySQL configurations
@app.route("/home/<string:db_name>/", methods=['GET'])
def db_show(db_name):
conn = MySQLdb.connect("host","user","password")
conn.select_db(db_name)
cur = conn.cursor()
sql = "SELECT user_id FROM activity_log"
cur.execute(sql)
data = cur.fetchone()
return data
if __name__ == "__main__":
app.run(debug=True)
但我有错误&#34; TypeError: 'long' object is not callable
&#34;。
问题:任何人都可以给我提示来修复此错误吗?或者可以按照我使用它的方式使用conn.select_db()
吗?感谢
错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1615, in full_dispatch_request
return self.finalize_request(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1630, in finalize_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1740, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 885, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/usr/local/lib/python2.7/dist-packages/werkzeug/test.py", line 884, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'long' object is not callable