pythonoracle-databasecx-oraclepython-oracledb

Connecting to Oracle SQL Database From Python Without cx-oracle


I need to run a SQL script from python (Jupyter) and need to connect to an existing Oracle database for the same. I am trying to automate the process, as the output of the SQL will serve as input for my statistical modelling code in Jyputer. However, for this, I need to connect to Oracle, but my organization doesn't have the cx_oracle library in the python package. Is there another way to run SQL script from python in Oracle?

I tried using pyodbc as below, but still getting error, although all supplied parameters are correct. The driver I have installed is Oracle in OraClient18Home1_32bit.

import pyodbc
cnxn = pyodbc.connect('DRIVER={Oracle in OraClient18Home1};DBQ=sinarrtou01-sc.sg.xx.com:1700/SGART4U_app.sg.xx.com;UID=DASKUMA;PWD=######')
cursor = cnxn.cursor()

Error I get is:

InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')


Solution

  • cx-oracle for Python has been deprecated and replaced with python-oracledb

    Another alternative would be to be to simply use the requests library to make REST API calls to get your data out of the database.