On Dec 18, 2011, at 6:29 AM, Florent Angebault wrote:

> Hello.
> 
> I tried many different configurations to connect to mysql5 server using 
> python3.2 and sqlalchemy 0.7.4 but couldn't have success.
> I always end with an error due to the fact that some string data is of type 
> 'bytes' instead of 'str'.
> 
> Below are 2 test cases that both fail.
> The first one uses PyMySQL3-0.5 and the second one uses 
> mysql-connector-0.3.2-devel.
> I don't know if I made mistakes with my configuration, or if it's a bug I 
> should report.
> 
> If I made a mistake, I'd be glad if someone could give me a link to the 
> appropriate documentation.
> If it's a bug, I don't know where I should report it: sqlalchemy, 
> mysqlconnector or pymysql project?


OK well take a look at supported DBs:

http://www.sqlalchemy.org/docs/core/engines.html#supported-databases

The only drivers supported for MySQL + Py3K are OurSQL and 
MySQL-connector/python.  In particular OurSQL runs pretty well and is on our 
continuous integration environment, with not quite all but most tests passing.

As far as pymysql, that it says "development" there means we just haven't 
gotten to test this driver with SQLAlchemy yet.   There's typically some 
configuration flags that need to be made in the dialect to give the driver what 
it expects.   It looks like there's some "encode" flags on that driver that 
just need to be flipped off when Py3K is in use.

I tried getting some of this to work but there seem to be other 
incompatibilities with PyMysql, namely it's raising exceptions in a way that's 
incompatible when Python 3 is run, breaking our ability to extract the error 
code correctly as "exception.args[0]" (I've added ticket: 
https://github.com/petehunt/PyMySQL/issues/94 for that).  Also the fact that 
it's published as two separate packages on Pypi (there should be just one 
package that uses 2to3 for Py3K), both of which appear to have problems with 
the Python "tarfile" module, isn't inspiring too much confidence at the moment. 
  So I'd stick with one of the other packages for now.




> 
> Here are two of my many attempts.
> (they are also visible here: http://bpaste.net/show/21027/)
> >>> from sqlalchemy import create_engine
> >>> engine = create_engine('sqlite:///:memory:')
> >>> engine.execute("select 'cassé !'").fetchall()
> [('cassé !',)]
> >>> engine = create_engine('mysql+pymysql://guest@192.168.222.1/test')
> >>> engine.execute("select 'cassé !'").fetchall()
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2298, in execute
>     connection = self.contextual_connect(close_with_result=True)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2342, in contextual_connect
>     self.pool.connect(),
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 210, in connect
>     return _ConnectionFairy(self).checkout()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 371, in __init__
>     rec = self._connection_record = pool._do_get()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 697, in _do_get
>     con = self._create_connection()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 174, in _create_connection
>     return _ConnectionRecord(self)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 259, in __init__
>     pool.dispatch.first_connect.exec_once(self.connection, self)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/event.py",
>  line 262, in exec_once
>     self(*args, **kw)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/event.py",
>  line 271, in __call__
>     fn(*args, **kw)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/strategies.py",
>  line 167, in first_connect
>     dialect.initialize(c)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/dialects/mysql/base.py",
>  line 1889, in initialize
>     default.DefaultDialect.initialize(self, connection)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/default.py",
>  line 176, in initialize
>     self._get_default_schema_name(connection)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/dialects/mysql/base.py",
>  line 1854, in _get_default_schema_name
>     return connection.execute('SELECT DATABASE()').scalar()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1405, in execute
>     params)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1582, in _execute_text
>     statement, parameters
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1639, in _execute_context
>     context)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/default.py",
>  line 332, in do_execute
>     cursor.execute(statement, parameters)
>   File 
> "/usr/local/lib/python3.2/dist-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py",
>  line 105, in execute
>     query = query % escaped_args
> TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'
> >>> engine = create_engine('mysql+mysqlconnector://guest@192.168.222.1/test')
> >>> engine.execute("select 'cassé !'").fetchall()
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2298, in execute
>     connection = self.contextual_connect(close_with_result=True)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2342, in contextual_connect
>     self.pool.connect(),
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 210, in connect
>     return _ConnectionFairy(self).checkout()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 371, in __init__
>     rec = self._connection_record = pool._do_get()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 697, in _do_get
>     con = self._create_connection()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 174, in _create_connection
>     return _ConnectionRecord(self)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/pool.py",
>  line 259, in __init__
>     pool.dispatch.first_connect.exec_once(self.connection, self)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/event.py",
>  line 262, in exec_once
>     self(*args, **kw)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/event.py",
>  line 271, in __call__
>     fn(*args, **kw)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/strategies.py",
>  line 167, in first_connect
>     dialect.initialize(c)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/dialects/mysql/base.py",
>  line 1889, in initialize
>     default.DefaultDialect.initialize(self, connection)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/default.py",
>  line 176, in initialize
>     self._get_default_schema_name(connection)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/dialects/mysql/base.py",
>  line 1854, in _get_default_schema_name
>     return connection.execute('SELECT DATABASE()').scalar()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1405, in execute
>     params)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1582, in _execute_text
>     statement, parameters
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 1665, in _execute_context
>     result = context.get_result_proxy()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/default.py",
>  line 634, in get_result_proxy
>     return base.ResultProxy(self)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2723, in __init__
>     self._init_metadata()
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2730, in _init_metadata
>     self._metadata = ResultMetaData(self, metadata)
>   File 
> "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/engine/base.py",
>  line 2608, in __init__
>     if keymap.setdefault(name.lower(), rec) is not rec:
> TypeError: unhashable type: 'bytearray'
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to