MySQL: encoding for client connection causes deprecation warning

Issue #1658 resolved
Former user created an issue

I'm using SQLAlchemy 0.5.7 and Python 2.6.1 (on WinXP), and when I'm trying set client encoding in MySQL connection URI,

create_engine('mysql:///mydb?charset=utf8')

then I get traceback as below:

....
  File "c:\python26\lib\site-packages\sqlalchemy-0.5.7-py2.6.egg\sqlalchemy\engine\__init__.py", line 223, in
create_engine
    return strategy.create(*args, **kwargs)
  File "c:\python26\lib\site-packages\sqlalchemy-0.5.7-py2.6.egg\sqlalchemy\engine\strategies.py", line 46, in
 create
    u = url.make_url(name_or_url)
  File "c:\python26\lib\site-packages\sqlalchemy-0.5.7-py2.6.egg\sqlalchemy\engine\url.py", line 137, in make_
url
    return _parse_rfc1738_args(name_or_url)
  File "c:\python26\lib\site-packages\sqlalchemy-0.5.7-py2.6.egg\sqlalchemy\engine\url.py", line 162, in _pars
e_rfc1738_args
    query = (len(tokens) > 1 and dict(cgi.parse_qsl(tokens[1](1)))) or None
  File "C:\Python26\Lib\cgi.py", line 191, in parse_qsl
    PendingDeprecationWarning)
PendingDeprecationWarning: cgi.parse_qsl is deprecated, use urlparse.parse_qsl instead

Comments (6)

  1. Mike Bayer repo owner

    this is a pendingdeprecationwarning which is off by default. You're turning them on using something like:

    warnings.filterwarnings("error", r'.*', PendingDeprecationWarning)
    

    dont do that !

  2. Former user Account Deleted
    • changed status to open
    • removed status

    I was hitting the same warning, because I followed the advice at http://www.sqlalchemy.org/docs/core/types.html#sqlalchemy.types.Unicode, which says to use the following:

    import warnings
    warnings.simplefilter('error')
    

    The catch is that now an error is thrown for this PendingDeprecationWarning, which is still being caused in 0.7.1 in that same file: sqlalchemy/engine/url.py, in _parse_rfc1738_args.

    The docs at the link above should be modified to use:

    import warnings
    from sqlalchemy.exc import SAWarning
    warnings.simplefilter("error", SAWarning)
    

    The warning type is the 2nd positional arg, there's no regexp arg. Doing it this way got me past the PDWarning and nailed the SAWarning I was looking for.

    Sorry for reopening this, wasn't sure if that's necessary to raise attention or if it would work OK to leave it closed while just adding this note. I read #1682 and it says this won't be fixed because cgi.parse_qsl is only in 2.6. But this is all, in my case, coming from SQLAlchemy-0.7.1-py2.7.egg ... and I have only python 2.7 installed. I don't know enough to conclude anything from that, but wanted to raise this information in case it was helpful. Thanks.

  3. Former user Account Deleted

    Great, thanks. Also, you didn't mention making a doc change as suggested above, but I think it would be a good idea. Although on the other hand it's always a good time for the user to learn about warnings.simplefilter and how it has more than one useful argument.

  4. Mike Bayer repo owner

    yeah I'd rather keep it easy in that way, also if I want to filter warnings I tend to filter on the string, so maybe using warnings.filterwarnings("error", "unicode") would be better here. I'd mostly want users to just go read Python's docs so that they know how to control warnings going forward.

  5. Log in to comment