Python Forum
Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: OR
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: OR
#1
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 : Below is the TNS file content. Please refer

Thanks,
Dinesh

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Sony-PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)

ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to LDAP through Python ranjansanyal2007 0 408 Oct-09-2023, 05:21 PM
Last Post: ranjansanyal2007
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,332 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Connecting c++ and python Mawixy 1 1,160 Apr-17-2022, 02:34 PM
Last Post: deanhystad
  Encrypting Oracle Passwords / Python Library for That? bmccollum 1 2,573 Jun-11-2021, 07:59 PM
Last Post: Larz60+
  cx_Oracle.DatabaseError: Error while trying to retrieve text from error ORA-01804 rajeshparadker 0 8,636 Nov-12-2020, 07:34 PM
Last Post: rajeshparadker
  Calling Oracle REST SQL from Python johnjacob 2 2,031 Nov-05-2020, 04:19 AM
Last Post: johnjacob
  Python to Oracle Conn Issue chvsnarayana 2 37,996 Sep-06-2020, 04:33 PM
Last Post: Larz60+
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,489 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  Connection timed out error when connecting to SQL server kenwatts275 2 3,317 Jun-02-2020, 07:35 PM
Last Post: bowlofred
  Load table from Oracle to MYSQL using python himupant94 0 1,637 May-12-2020, 04:50 PM
Last Post: himupant94

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020