My envirionment is SQLAlchemy 0.7.9, pyodbc 3.0.2, Python 3.2, and SQL Server 2008 R2 running on Windows 7
I have the following Python (details of the connection url removed - the connection to the db succeeds):
from sqlalchemy import create_engine, MetaData, Table
engine = create_engine(dburl, description_encoding=none)
meta = MetaData(engine)
meta.reflect(None, None, False, ['Exercise'])
The final line causes the following exception:
Traceback (most recent call last):
File "C:\Subversion\ProFormGraphMetrics\ProFormGraphMetrics\ProFormGraphMetrics.py", line 13, in <module> meta.reflect(None,None,False,['Exercise'])
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\schema.py", line 2507, in reflect connection=conn))
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\base.py", line 2511, in table_names return self.dialect.get_table_names(conn, schema)
File "<string>", line 1, in <lambda> File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\reflection.py", line 39, in cache return fn(self, con, *args, **kw)
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\dialects\mssql\base.py", line 1233, in get_table_names table_names = [r[0] for r in connection.execute(s)]
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\base.py", line 1449, in execute params)
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\base.py", line 1584, in _execute_clauseelement compiled_sql, distilled_params
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\base.py", line 1651, in _execute_context None, None)
File "C:\Python32\lib\site-packages\sqlalchemy-0.7.9-py3.2.egg\sqlalchemy\engine\base.py", line 1843, in _handle_dbapi_exception from e
sqlalchemy.exc.StatementError: 'str' object has no attribute 'decode' (original
cause: AttributeError: 'str' object has no attribute 'decode') 'SELECT [TABLES_1
].[TABLE_NAME] \nFROM [INFORMATION_SCHEMA].[TABLES] AS [TABLES_1] \nWHERE [TABLE
S_1].[TABLE_SCHEMA] = ? AND [TABLES_1].[TABLE_TYPE] = ? ORDER BY [TABLES_1].[TAB
LE_NAME]' []
Since (from my reading of the Python documentation) str.decode() is removed in Python 3.2 I suspect the 2to3 conversion script is not being run on install of sqlalchemy. I have installed SQLAlchemy with both easy_install and by running "Python setup.py install" on the downloaded source but have not been able to get beyond this error.
Any help or guidance would be most appreciated.