我正在
cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred error while connecting oracle from python.
我已经安装了python 3.7.0和instantclient_11_2。
以下是我正在做的过程,
import cx_Oracle
dsn_tns = cx_Oracle.makedsn( '<ip>', 1521, service_name = '<given service name>')
connection = cx_Oracle.connect('user', 'pwd', dsn_tns)
我已将系统设置为可验证
PATH
,其中 oci.dll
存在。
可能出了什么问题?
尝试:
connection = cx_Oracle.connect('user', 'pwd', cx_Oracle.makedsn( '<ip>', '1521',None,'<given service name>'))
看起来一样,但在我的 ubuntu 服务器上工作不同。
还要确保将端口放在“ ”之间
如果数据库驻留在同一台计算机上,您还应该能够使用以下连接字符串:
connection = cx_Oracle.connect('user/pwd@localhost/service_name')
请注意,service_name 值是必需的。不能使用空字符串!