Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: ORA-12154: TNS:co

DINESH EDVINOct 25 2018 — edited Oct 25 2018

Hi,

I am trying to connect the Oracle database from Python IDLE with below code but getting an error.

Can anyone help me on this.

import cx_Oracle

conn = cx_Oracle.connect('hr/hr@Sony-PC/XE')

print(conn)

Error:

Traceback (most recent call last):

File "D:/Python/25_10(2).py", line 3, in <module>

conn = cx\_Oracle.connect('hr/hr@Sony-PC/XE')

cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

I have done the below prerequisites before executing the code.

1.Installed Oracle 11 g 64 bit Express edition.(created username/password: hr/hr)

2.Installed Python 3.7.1 64 bit.(automatically the PATH has been set)

3.Installed the cx_Oracle package using below command.

python -m pip install cx_Oracle --upgrade pip

(currently this is having 18.1 version)

4.Downloaded the Oracle Instant client 64 bit and set the PATH in system variable. ;C:\instantclient-basic-windows.x64-11.2.0.4.0\instantclient_11_2

5.Installed the Microsoft Windows Redistributables for client library.

6.Tried executing the below code but getting error.

import cx_Oracle

conn = cx_Oracle.connect('hr/hr@Sony-PC/XE')

print(conn)

Note : attached is the TNS file content. Please refer

Thanks,

DineshTNS.jpg

This post has been answered by Sdhamoth-Oracle on Oct 25 2018
Jump to Answer
Comments
Post Details
Added on Oct 25 2018
4 comments
37,356 views