how to use `charset` and `encoding` in `create_engine` of SQLAlchemy (to create pandas dataframe)?

后端 未结 4 1830
清酒与你
清酒与你 2020-12-17 10:48

I am very confused with the way charset and encoding work in SQLAlchemy. I understand (and have read) the difference between charsets and encodings, and I h

4条回答
  •  情歌与酒
    2020-12-17 11:45

    This works for me .

    from sqlalchemy import create_engine
    from sqlalchemy.engine.url import URL
    
    db_url = {
        'database': "dbname",
        'drivername': 'mysql',
        'username': 'myname',
        'password': 'mypassword',
        'host': '127.0.0.1',
        'query': {'charset': 'utf8'},  # the key-point setting
    }
    
    engine = create_engine(URL(**db_url), encoding="utf8")
    

提交回复
热议问题