运行GAE开发服务器时,本地MySQLdb连接在AttributeError for paramstyle时失败 [英] Local MySQLdb connection fails with AttributeError for paramstyle when running GAE development server
问题描述
我正在使用Flask-Alchemy构建一个GAE Flask应用程序,针对Cloud SQL,并运行 dev_appserver
来测试构建应用程序。
$ b
但是,如果将 SQLALCHEMY_DATABASE_URI
设置为 mysql + gaerdbms:/// appname?instance = instanceid
URL,当尝试调用 db.create_all()
时,我得到以下回溯:
Traceback(最近一次调用的最后一个):
#为简洁省略前面的行
文件/Project/app/foo.bar/foo/bar/admin/ __init__.py,第26行,在init_db
db.create_all()
文件/Project/app/distlib/flask_sqlalchemy/__init__.py,第856行,在create_all
self中。 _execute_for_all_tables(app,bind,'create_all')
文件/Project/app/distlib/flask_sqlalchemy/__init__.py,第848行,在_execute_for_all_tables
op(bind = self.get_engine(app,bind ),tables = tables)
文件/Project/app/distlib/flask_sqlalchemy/__init__.py,第797行,在get_eng ine
返回connector.get_engine()
文件/Project/app/distlib/flask_sqlalchemy/__init__.py,第473行,在get_engine
self._engine = rv = sqlalchemy.create_engine( info,** options)
文件/Project/app/distlib/sqlalchemy/engine/__init__.py,第332行,在create_engine
return strategy.create(* args,** kwargs)
文件/Project/app/distlib/sqlalchemy/engine/strategies.py,第69行,创建
dialect = dialect_cls(** dialect_args)
文件/ Project / app / distlib /sqlalchemy/dialects/mysql/base.py,第1986行,在__init__
default.DefaultDialect .__ init __(self,** kwargs)
文件/ Project / app / distlib / sqlalchemy / engine / $ _ $ __init__
self.paramstyle = self.dbapi.paramstyle
AttributeError:'模块'对象没有属性'paramstyle'
什么给了?为什么需要(DB-API 2.0) paramstyle
属性缺失?
<这意味着 MySQLdb
模块缺失并且无法导入。 GAE SDK本身不带有MySQLdb客户端库;安装MySQLdb(根据SDK文档中的说明,):
venv / bin / pip安装mysql-python
或使用您的操作系统包管理器在您的系统python中安装MySQLdb。
$ b 错误是由Google
google引起的。 appengine.api.rdbms_mysqldb
模块作为存根,当导入MySQLdb时不具有 paramstyle
属性
失败。提供了一个存根 connect()
函数,它会引发一个更有帮助的异常,但由于与SQLAlchemy的不良交互,错误的信息量会少得多。 I'm building a GAE Flask application with Flask-Alchemy, against Cloud SQL, and running dev_appserver
to test the application as I build it.
However, if I set the SQLALCHEMY_DATABASE_URI
to a mysql+gaerdbms:///appname?instance=instanceid
URL, I get the following traceback when trying to call db.create_all()
:
Traceback (most recent call last):
# earlier lines omitted for brevity
File "/Project/app/foo.bar/foo/bar/admin/__init__.py", line 26, in init_db
db.create_all()
File "/Project/app/distlib/flask_sqlalchemy/__init__.py", line 856, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/Project/app/distlib/flask_sqlalchemy/__init__.py", line 848, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), tables=tables)
File "/Project/app/distlib/flask_sqlalchemy/__init__.py", line 797, in get_engine
return connector.get_engine()
File "/Project/app/distlib/flask_sqlalchemy/__init__.py", line 473, in get_engine
self._engine = rv = sqlalchemy.create_engine(info, **options)
File "/Project/app/distlib/sqlalchemy/engine/__init__.py", line 332, in create_engine
return strategy.create(*args, **kwargs)
File "/Project/app/distlib/sqlalchemy/engine/strategies.py", line 69, in create
dialect = dialect_cls(**dialect_args)
File "/Project/app/distlib/sqlalchemy/dialects/mysql/base.py", line 1986, in __init__
default.DefaultDialect.__init__(self, **kwargs)
File "/Project/app/distlib/sqlalchemy/engine/default.py", line 124, in __init__
self.paramstyle = self.dbapi.paramstyle
AttributeError: 'module' object has no attribute 'paramstyle'
What gives? Why is the (DB-API 2.0 required) paramstyle
attribute missing?
This means the MySQLdb
module is missing and failed to import. The GAE SDK does not itself come with the MySQLdb client library; install MySQLdb (as instructed in the SDK documentation):
venv/bin/pip install mysql-python
or use your OS package manager to install MySQLdb in your system python.
The error is caused by the Google google.appengine.api.rdbms_mysqldb
module, acting as a stub, not having a paramstyle
attribute when import MySQLdb
fails. A stub connect()
function is provided that'll raise a more helpful exception, but due to an unfortunate interaction with SQLAlchemy the error there is a lot less informative.
这篇关于运行GAE开发服务器时,本地MySQLdb连接在AttributeError for paramstyle时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!