Another UnicodeEncodeError when using pandas method to_sql with MySQL

后端 未结 2 1008
春和景丽
春和景丽 2020-12-21 00:48

I posted on stack overflow a few days ago with a similar problem (which was solved), and I\'m not sure what the proper etiquette is here, but I\'m making a new post.

相关标签:
2条回答
  • 2020-12-21 01:02

    \u2013 is an "en dash". Perhaps some word processor is creating that? Perhaps you would be happy enough with a simple -?

    See https://docs.sqlalchemy.org/en/latest/dialects/mysql.html#mysql-unicode

    0 讨论(0)
  • 2020-12-21 01:29

    Well, within an hour of posting my question, I already figured it out. Maybe I should have done a bit more research before posting.

    The problem is that sqlalchemy needs to be configured to use utf-8 encoding. The solution in the above code would be to change line 3 to:

    engine = create_engine('mysql://root:@localhost/testdb?charset=utf8', encoding = 'utf-8')
    
    0 讨论(0)
提交回复
热议问题