V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yykrlc
V2EX  ›  Python

py3-flask-pymysql 兼容问题(use_native_unicode).py

  •  
  •   yykrlc · 2020-09-18 11:34:19 +08:00 · 1558 次点击
    这是一个创建于 1288 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python >=3.7.9
    Flask 1.12
    Flask-SQLAlchemy 2.4.4
    Flask-WTF 0.14.3
    flask_migrate 2.5.3
    flask_script 2.0.6
    flask_restful 0.3.8
    requests
    redis
    pymysql 0.10.1
    
    连接 mysql

    MDB_URI = 'mysql+pymysql://........

    报错信息:
    TypeError: Invalid argument(s) 'use_native_unicode' sent to create_engine(), using configuration MySQLDialect_mysqldb/QueuePool/Engine.  Please check that the keyword arguments are appropriate for this combination of components.
    

    涉及源码 site-packages/sqlalchemy/engine/strategies.py", line 173, in create

    # all kwargs should be consumed
    
            if kwargs:  # print(kwargs) == {"use_native_unicode":''}
                raise TypeError(
                    "Invalid argument(s) %s sent to create_engine(), "
                    "using configuration %s/%s/%s.  Please check that the "
                    "keyword arguments are appropriate for this combination "
                    "of components."
                    % (
                        ",".join("'%s'" % k for k in kwargs),
                        dialect.__class__.__name__,
                        pool.__class__.__name__,
                        engineclass.__name__,
                    )
                )
    
            engine = engineclass(pool, dialect, u, **engine_args)
    

    db = SQLAlchemy() flask_sqlalchemy/init.py

    # 默认 use_native_unicode=True
    def __init__(self, app=None, use_native_unicode=True, session_options=None,
                     metadata=None, query_class=BaseQuery, model_class=Model,
                     engine_options=None):
    

    是不是 flask_sqlalchemy 和 sqlalchemy 兼容问题,除了改源码还有别的解决方法吗。

    2 条回复    2020-09-18 16:00:07 +08:00
    rogwan
        1
    rogwan  
       2020-09-18 12:28:55 +08:00
    应该是版本问题,把版本号稍微降低一点试试
    Kobayashi
        2
    Kobayashi  
       2020-09-18 16:00:07 +08:00
    应该是二者兼容问题,我看了一眼在 flask_sqlalchemy 在 3.0 (dev) 中去除了这个初始化参数。猜测是上游 sqlalchemy 更新了,这个参数不能用了?

    flask_sqalchemy 依赖写得比较宽松,install_requires=["Flask>=0.10", "SQLAlchemy>=0.8.0"].

    建议把 sqlalchemy 版本列出来,逐步往回降试试。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2821 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:33 · PVG 21:33 · LAX 06:33 · JFK 09:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.