pythonmysqlsqlobject

SQLObject throws: Unknown database 'dbname?charset=utf8'


I've got third-party Python script, it looks like it has to connect to MySQL database by means of SQLObject package.

Considering I've provided correct DSN, the script throws

sqlobject.dberrors.OperationalError: Unknown database 'dbname?charset=utf8'

I've traced the problem to this piece of code

ar['charset'] = 'utf8'
conn = connectionForURI(uri, **ar)

which calls this function.

And it connects fine when ar['charset'] = 'utf8' is commented, so no query string is provided.

I have this issue on Windows,

What exactly is going on there, and how it is supposed to be fixed? Does the problem lie in dependencies or the script itself?


Solution

  • I have done some research and found out that recent version of SQLObject uses the following code to extract connection parameters from URI. Unfortunately, urlparse function works that way so path that is used as DB name further parsed with a query string.

    As a workaround for this issue, I could suggest passing DB encoding parameter explicitly to the connection object as follow:

    conn = connectionForURI(uri)
    conn.dbEncoding = 'utf-8'
    

    It might help but it's worth to make a pull request to fix DB name extraction from URI.

    UPD: Older version like 2.x uses a different code to parse connection URL which works well.