简体   繁体   English

无法使用python 3.4连接到Oracle

[英]Cannot connect to Oracle using python 3.4

I just started to learn python and try to connect to oracle 11g, but I always get following error 我刚刚开始学习python并尝试连接到oracle 11g,但是我总是收到以下错误

cx_Oracle.InternalError: No Oracle error? cx_Oracle.InternalError:没有Oracle错误?

Here is my simple script to connect to oracle 这是我连接到oracle的简单脚本

import cx_Oracle as oracle
con = oracle.connect('user/password@ip:port/service')

Already try to look for any reference in other sites including here but can't find the solution. 已经尝试在其他站点(包括此处)中查找任何参考,但找不到解决方案。 I don't think I have connection issue to oracle, because I use the same PC to connect to oracle using PHP. 我认为我与oracle没有连接问题,因为我使用同一台PC通过PHP连接到oracle。 Any advise would be appreciated, thanks. 任何建议,将不胜感激,谢谢。

One thing to keep in mind anytime you work with Oracle is that they use a proprietary connection protocol TNS (Transparent Network Substrate). 在您与Oracle一起工作时,要记住的一件事是它们使用专有的连接协议TNS (透明网络基质)。 Therefore, you might need to use the cx_Oracle.makedsn(ip, port, SID) method and then pass it to cx_Oracle.connect() method to create your connection. 因此,您可能需要使用cx_Oracle.makedsn(ip, port, SID)方法,然后将其传递给cx_Oracle.connect()方法以创建连接。 Thus the general format on how to set up Oracle connection is: 因此,有关如何建立Oracle连接的一般格式为:

import cx_Oracle

ip = 'xxx.xxx.xx.xxx'
port = 'xxxx'
SID = 'SID'
username = 'username'
password = 'password'

dsn_tns = cx_Oracle.makedsn(ip, port, SID)
db = cx_Oracle.connect(username, password, dsn_tns)

This is assuming you have already gotten cx_Oracle to work and import properly, which can be finicky depending on your environment. 这是假设您已经使cx_Oracle正常工作和导入,根据您的环境,这可能会很挑剔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM