Invalid argument(s) 'pool_size' sent to create_engine(), using configuration

Invalid argument(s) 'pool_size' sent to create_engine(), using configuration

 

我们这里测试的是create_engine缺乏参数。

 

down votefavorite

I create sqlalchemy engine connecting to MySQL database. I want to specify charset as create_engine argument.

If I use create_engine liKe that:

create_engine('mysql+mysqldb://pd:pd@localhost/pd?charset=utf8') 

then all is fine. But, when I use it like that:

create_engine('mysql+mysqldb://pd:pd@localhost/pd', charset='utf8') 

then I get the following error:

 

from sqlalchemy.pool import SingletonThreadPool

engine = create_engine('sqlite:///mydb.db', poolclass=SingletonThreadPool)

Passing in an explicit pool class also works on 0.6. Personally, I'd use exception handling here:

try:
    engine = create_engine(URL, pool_size=10)
except TypeError:
    # The pool_size argument won't work for the default SQLite setup in SQLAlchemy 0.7, try without
    engine = create_engine(URL)

最后发现是SQLALCHEMY_DATABASE_URI 这个参数没有,补上就可以了。

也有可能是别的原因。

修改方法:

SQLALCHEMY_DATABASE_URI = 'mysql://root:[email protected]:3306/bd_new?charset=utf8&auth_plugin=mysql_native_password'

你可能感兴趣的:(python)