python cx_Oracle连接oracle常见错误

连接方式:conn = cx_Oracle.connect(‘user’,‘passwd’,‘ip:port/service_name’)

错误一:DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: “C:\Program Files (x86)\Oracle\oci.dll is not the correct architecture”. See https://oracle.github.io/odpi/doc/installation.html#windows for help
措施:

1.首先确保python版本和oracle客户端,instantclient版本一致,都为同样的64位或者32位

oracle instantclient 64位安装包下载链接,提取码:nbvs,如失效请留言

2.查看环境变量的配置
2.1 ORACLE_HOME

E:\oracle\instantclient_11_2

在这里插入图片描述

2.2 Path中添加

C:\Program Files (x86)\Oracle

在这里插入图片描述

-------------------------------------------------------------------------------------------

错误二:ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
1.打开E:…\instantclient_11_2\tnsnames.ora文件

xxx =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ip)(PORT = 端口号))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xxx)
)
)

确保连接信息中的ip,端口,服务名称在你的tnsnames.ora文件中是存在的

2.如果还不行 看一下环境变量配置
2.1 ORACLE_HOME

E:\oracle\instantclient_11_2
在这里插入图片描述

重启,连接!!!

发布了45 篇原创文章 · 获赞 1 · 访问量 1764

猜你喜欢

转载自blog.csdn.net/wzj_wp/article/details/103383865