Search code examples
python-3.xoracle-databaseubuntu-18.04cx-oracle

Oracle database connection using python is not Working


I'm trying to connect to the oracle database in python using cx_Oracle. But I'm stuck with the below error.

enter image description here

For reference my code

  def runQuery(self,query):
        with cx_Oracle.connect(config.username,config.password,config.dsn,encoding=config.encoding) as connection:
            try:
                print(connection.version)
            except cx_Oracle.Error as error:
                print(error)

Config File

username = 'dummy'
password = 'dummy'
dsn = 'dummy@//localhost:1521/ORCLCDB.localdomain'
port = 1512
encoding = 'UTF-8'

For additional knowledge, using the docker image of the oracle database for this purpose.

May I know how can clear the issue and proceed and could someone please help to find what is missing in my implementation.


Solution

  • Do you have Oracle Instant Client installed? Looks like you are using Ubuntu. For an RPM-based distro, installation would look like this. There are instructions out there to install Oracle Instant Client on Ubuntu as well, but perhaps you are better of putting your Python code and cx_Oracle in a container as well, as Chris Jones explains here.