SQLAlchemy和Oracle 12c连接问题

时间:2016-10-12 17:40:06

标签: python oracle sqlalchemy oracle12c

我在Python 3.5上使用SQLAlchemy CORE(1.0.12)来连接我组织的Oracle数据库。在我的组织将Oracle数据库从11g升级到12c之前,我的数据库脚本没有问题。升级后,我在尝试将数据插入现有表时通常会遇到以下错误。

sqlalchemy.exc.OperationalError: (cx_Oracle.OperationalError) ORA-03135: connection lost contact
Process ID: 10355
Session ID: 184 Serial number: 60376

我在升级过程中没有更改任何SQLAlchemy脚本,并且总是没有错误,通常只在我尝试插入大型数据集时才会发生。我研究了与ORA-03135错误代码相关的问题,并确认我没有遇到任何防火墙问题(我有时可以连接)或超时(错误提示会在几秒钟内出现,这对于超时来说太快了。)

是否有其他人遇到此问题并找到了解决方案?

Traceback (most recent call last):
  File "C:\ross\repository\Analytics\OptTekSQL\run.py", line 5, in <module>
'Demand Analysis 8/17/16')
  File "C:\ross\repository\Analytics\OptTekSQL\optsql\data_load.py", line 43, in demand_output_load
s.insert_df(df, 'ACCDC_DEMAND_OUTPUTS')
  File "C:\ross\repository\Analytics\OptTekSQL\optsql\base.py", line 38, in insert_df
self.eng.connect().execute(ins, data)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\engine\base.py", line 914, in execute
return meth(self, multiparams, params)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\sql\elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\engine\base.py", line 1010, in _execute_clauseelement
compiled_sql, distilled_params
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\engine\base.py", line 1146, in _execute_context
context)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\engine\base.py", line 1341, in _handle_dbapi_exception
exc_info
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\util\compat.py", line 200, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\util\compat.py", line 183, in reraise
raise value.with_traceback(tb)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\engine\base.py", line 1116, in _execute_context
context)
  File "C:\Users\palmer\AppData\Local\Continuum\Anaconda2\envs\py3\lib\site-packages\sqlalchemy\dialects\oracle\cx_oracle.py", line 964, in do_executemany
cursor.executemany(statement, parameters)

1 个答案:

答案 0 :(得分:0)

我们遇到了这个问题,以下解决方法可以防止错误:

在oracle数据库服务器上,将参数添加到sqlnet.ora文件中(使用如下的大数字以防止超时):

SQLNET.SEND_TIMEOUT=600000

在客户端通过python连接到数据库的sqlnet.ora上添加相同的参数。