farcepest / MySQLdb1

MySQL database connector for Python (legacy version)

Home Page:https://sourceforge.net/projects/mysql-python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LookupError: unknown encoding: koi8r. Is possible to add that encoding?

foger opened this issue · comments

Hi.
I know that utf-8 is a good choice, but i have old not mine project written in Perl and that stores data in MySQL in KOI8-R encoding. Python supports this encoding, MySQLdb - not :( How can i add KOI8-R encoding support?

Note: MySQL knows it as "koi8r", Python as "koi8-r" or "koi8_r". If I set charset='koi8-r' in database connection i get an error:
_mysql_exceptions.OperationalError: (2019, "Can't initialize character set koi8-r (path: /usr/share/mysql/charsets/)"). Yes, because only koi8r.xml file there and mysql knows koi8r encoding.

If I set charset='koi8r' as mysql knows in database connection i get:

  File "mdbtest.py", line 10, in <module>
    cur.execute("SELECT fio FROM user WHERE id = %s", (36500,))
  File "/home/foger/Dev/Python/lib/python3.6/site-packages/MySQLdb/cursors.py", line 243, in execute
    query = query.encode(db.encoding, 'surrogateescape')
LookupError: unknown encoding: koi8r

MySQL example:

mysql> set names koi8r;
Query OK, 0 rows affected (0.00 sec)

Please help!

This project is not maintained for a long time.
Use mysqlclient instead. It's a fork of this project.