sql查询报错

来源:4-8 数据库ORM

SuperMan_GYD

2020-02-06

代码:def hello():
sql=text(“SELECT * FROM ‘smess’”)
result=db.engine.execute(sql)
for row in result:
app.logger.info(row)
return ‘Hello World2’

报错:E:\Python\python.exe "E:/IDEA/pycharm/project/practice flask/order/flask_pra.py"
E:\Python\lib\site-packages\flask_sqlalchemy_init_.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ’

  • Serving Flask app “flask_pra” (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: on
  • Restarting with stat
    E:\Python\lib\site-packages\flask_sqlalchemy_init_.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
    'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ’
  • Debugger is active!
  • Debugger PIN: 128-585-624
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    127.0.0.1 - - [06/Feb/2020 22:59:58] “GET /api/hello HTTP/1.1” 500 -
    Traceback (most recent call last):
    File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 1246, in _execute_context
    cursor, statement, parameters, context
    File “E:\Python\lib\site-packages\sqlalchemy\engine\default.py”, line 588, in do_execute
    cursor.execute(statement, parameters)
    File “E:\Python\lib\site-packages\MySQLdb\cursors.py”, line 209, in execute
    res = self._query(query)
    File “E:\Python\lib\site-packages\MySQLdb\cursors.py”, line 315, in _query
    db.query(q)
    File “E:\Python\lib\site-packages\MySQLdb\connections.py”, line 239, in query
    _mysql.connection.query(self, query)
    MySQLdb._exceptions.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘smess’’ at line 1”)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “E:\Python\lib\site-packages\flask\app.py”, line 2463, in call
return self.wsgi_app(environ, start_response)
File “E:\Python\lib\site-packages\flask\app.py”, line 2449, in wsgi_app
response = self.handle_exception(e)
File “E:\Python\lib\site-packages\flask\app.py”, line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File “E:\Python\lib\site-packages\flask_compat.py”, line 39, in reraise
raise value
File “E:\Python\lib\site-packages\flask\app.py”, line 2446, in wsgi_app
response = self.full_dispatch_request()
File “E:\Python\lib\site-packages\flask\app.py”, line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File “E:\Python\lib\site-packages\flask\app.py”, line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “E:\Python\lib\site-packages\flask_compat.py”, line 39, in reraise
raise value
File “E:\Python\lib\site-packages\flask\app.py”, line 1949, in full_dispatch_request
rv = self.dispatch_request()
File “E:\Python\lib\site-packages\flask\app.py”, line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File “E:\IDEA\pycharm\project\practice flask\order\flask_pra.py”, line 38, in hello
result=db.engine.execute(sql)
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 2182, in execute
return connection.execute(statement, *multiparams, **params)
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 982, in execute
return meth(self, multiparams, params)
File “E:\Python\lib\site-packages\sqlalchemy\sql\elements.py”, line 293, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 1101, in _execute_clauseelement
distilled_params,
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 1250, in _execute_context
e, statement, parameters, cursor, context
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 1476, in _handle_dbapi_exception
util.raise_from_cause(sqlalchemy_exception, exc_info)
File “E:\Python\lib\site-packages\sqlalchemy\util\compat.py”, line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File “E:\Python\lib\site-packages\sqlalchemy\util\compat.py”, line 152, in reraise
raise value.with_traceback(tb)
File “E:\Python\lib\site-packages\sqlalchemy\engine\base.py”, line 1246, in _execute_context
cursor, statement, parameters, context
File “E:\Python\lib\site-packages\sqlalchemy\engine\default.py”, line 588, in do_execute
cursor.execute(statement, parameters)
File “E:\Python\lib\site-packages\MySQLdb\cursors.py”, line 209, in execute
res = self._query(query)
File “E:\Python\lib\site-packages\MySQLdb\cursors.py”, line 315, in _query
db.query(q)
File “E:\Python\lib\site-packages\MySQLdb\connections.py”, line 239, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.ProgrammingError: (MySQLdb._exceptions.ProgrammingError) (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘smess’’ at line 1”)
[SQL: SELECT * FROM ‘smess’]
(Background on this error at: http://sqlalche.me/e/f405)
127.0.0.1 - - [06/Feb/2020 22:59:58] “GET /api/hello?debugger=yes&cmd=resource&f=style.css HTTP/1.1” 200 -
127.0.0.1 - - [06/Feb/2020 22:59:59] “GET /api/hello?debugger=yes&cmd=resource&f=jquery.js HTTP/1.1” 200 -
127.0.0.1 - - [06/Feb/2020 22:59:59] “GET /api/hello?debugger=yes&cmd=resource&f=debugger.js HTTP/1.1” 200 -
127.0.0.1 - - [06/Feb/2020 22:59:59] “GET /api/hello?debugger=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1” 200 -
127.0.0.1 - - [06/Feb/2020 22:59:59] “GET /api/hello?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
127.0.0.1 - - [06/Feb/2020 23:00:00] “GET /api/hello?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -

图片描述

图片描述

写回答

1回答

编程浪子

2020-02-07

你好 你把我下面复制进去和你对比下你就知道了

SELECT * FROM `smess`


1
2
SuperMan_GYD
复制了老师你的对了
2020-02-07
共2条回复

Python Flask构建微信小程序订餐系统(可用于毕设)

微信小程序 + Python Flask 打造订餐系统全栈应用,可用于毕设。

1732 学习 · 1913 问题

查看课程