在cx_Oracle / sqlalchemy中反映数据库表

时间:2018-07-03 17:56:29

标签: python docker sqlalchemy debian cx-oracle

我正尝试从python连接到基于debian的docker容器中运行的数据库。我提取了导致失败的代码:

import sqlalchemy

from db_tools import generate_sandbox_connection

con = generate_sandbox_connection('churn', 'PASSWORD')
metadata = sqlalchemy.MetaData()

report_lookup = sqlalchemy.Table('REPORT_LOOKUP',
                                  metadata,
                                  schema = 'SCHEMA',
                                  autoload = True,
                                  autoload_with = con)

这将导致以下输出:

Traceback (most recent call last):
  File "sqlalchemytest.py", line 43, in <module>
    autoload_with = sandb_con)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 457, in __new__
    metadata._remove_table(name, schema)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 452, in __new__
    table._init(name, metadata, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 534, in _init
    include_columns, _extend_on=_extend_on)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 547, in _autoload
    _extend_on=_extend_on
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2056, in run_callable

...

reraise(type(exception), exception, tb=exc_tb, cause=cause)
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
        context)
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 509, in do_execute
        cursor.execute(statement, parameters)
    sqlalchemy.exc.ProgrammingError: (cx_Oracle.ProgrammingError) positional and named binds cannot be intermixed [SQL: u'SELECT table_name, compression, compress_for FROM ALL_TABLES WHERE table_name = :table_name AND owner = :owner '] [parameters: {'owner': u'TRIP', 'table_name': u'CHURN_REPORT_LOOKUP'}] (Background on this error at: http://sqlalche.me/e/f405)

有人知道如何解决此问题吗?它在我的本地计算机上运行得很好,但是在docker实例中崩溃了。

1 个答案:

答案 0 :(得分:2)

这是最新的socket.on('challenge request')中的已知错误:

https://github.com/oracle/python-cx_Oracle/issues/199

目前,直到v6.4可用之前,只需降级到v6.4.1