我尝试了多次尝试连接Oracle数据库但仍然无法连接。以下是我的连接代码。但是,我可以通过终端连接Oracle DB,如下所示:
$ sqlplus64 uid/passwd@192.168.0.5:1521 / WSVC
我希望您分享与此问题相关的知识和经验。谢谢。
import os
os.chdir("/usr/lib/oracle/12.2/client64/lib")
import cx_Oracle
# 1st attempt
ip = '192.168.0.5'
port = 1521
SID = 'WSVC'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
# dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)
db = cx_Oracle.connect('uid', 'passwd', dsn_tns)
cursor = db.cursor()
-------------------------------------------------
# 2nd attempt
conn = "uid/passwd@(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.5)(PORT=1521)))(CONNECT_DATA=(SID=WSVC)(SRVR=DEDICATED)))"
db = cx_Oracle.connect(conn)
cursor = db.cursor()
------------------------------------------------------
# ERROR Description
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
答案 0 :(得分:1)
错误“无法获取Oracle环境句柄”是由于您的Oracle配置不正确。一些可以帮助您发现问题根源的事情:
ldd cx_Oracle.cpython-35m-x86_64-linux-gnu.so