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?

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.

Reply via email to