使用SQLAlchemy连接到QuickBooks吗?

时间:2018-12-19 22:31:53

标签: python sqlalchemy pyodbc qodbc

我正在尝试将sqlalchemy与QuickBooks一起使用,并使用qodbc驱动程序,并且在方言和架构方面遇到问题。

以下是显示问题的脚本:

from sqlalchemy import create_engine, MetaData, Table


def main():
    engine = create_engine("mssql+pyodbc://QuickBooks Data", echo=True)
    try:
        engine.connect()  # errors at "SELECT schema_name()" on connection
    except Exception:
        pass
    meta = MetaData()
    customer = Table('customer', meta, autoload=True, autoload_with=engine)


if __name__ == "__main__":
    main()

如果我在engine.connect()期间捕获了第一个异常并尝试反映Customer表,则会遇到另一个错误AttributeError: 'MSDialect_pyodbc' object has no attribute 'default_schema_name'(下面的完整回溯)。

只要我忽略engine.execute()异常,就可以使用engine.connect()进行查询。

是否存在一种编辑方言以添加默认模式的方法,或将其传递给SQLAlchemy的方法?如果是这样,对于QODBC应该是什么?

Traceback (most recent call last):
  File "C:/Users/jamie/PycharmProjects/cubey/cubey/scratch.py", line 15, in <module>
    main()
  File "C:/Users/jamie/PycharmProjects/cubey/cubey/scratch.py", line 11, in main
    customer = Table('customer', meta, autoload=True, autoload_with=engine)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\sql\schema.py", line 457, in __new__
    metadata._remove_table(name, schema)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\util\langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\util\compat.py", line 249, in reraise
    raise value
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\sql\schema.py", line 452, in __new__
    table._init(name, metadata, *args, **kw)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\sql\schema.py", line 534, in _init
    include_columns, _extend_on=_extend_on)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\sql\schema.py", line 547, in _autoload
    _extend_on=_extend_on
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\base.py", line 2056, in run_callable
    return conn.run_callable(callable_, *args, **kwargs)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\base.py", line 1545, in run_callable
    return callable_(self, *args, **kwargs)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\default.py", line 391, in reflecttable
    table, include_columns, exclude_columns, **opts)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\reflection.py", line 618, in reflecttable
    table_name, schema, **table.dialect_kwargs):
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\reflection.py", line 369, in get_columns
    **kw)
  File "<string>", line 2, in get_columns
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\engine\reflection.py", line 54, in cache
    ret = fn(self, con, *args, **kw)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\dialects\mssql\base.py", line 1747, in wrap
    dbname, owner = _owner_plus_db(dialect, schema)
  File "C:\Users\jamie\Miniconda3\envs\cubey\lib\site-packages\sqlalchemy\dialects\mssql\base.py", line 1766, in _owner_plus_db
    return None, dialect.default_schema_name
AttributeError: 'MSDialect_pyodbc' object has no attribute 'default_schema_name'

0 个答案:

没有答案