Error connecting Python to Oracle BD

Asked

Viewed 415 times

1

I am unable to connect Python to my oracle database.

Displays the following error :

import cx_Oracle
con = cx_Oracle.connect('topm/[email protected]/xe')
print (con.version)
con.close()
Traceback (most recent call last):

  File "<ipython-input-84-210d1be36a99>", line 2, in <module>
    con = cx_Oracle.connect('topm/[email protected]/xe')

DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "C:\oracle\product\10.2.0\client_1\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help

  • Apparently you are using a 64-bit operating system but your Oracle Client is 32-bit. Please install Oracle Client in version 64 bits at https://www.oracle.com/technetwork/topics/winx64soft-089540.html

1 answer

0


You are running different architectures of Python and Oracle. Since your Pyhton is 64 bits, your database also needs to be 64 bits. Do so:

  • Download the 64-bit Oracle client and install here at this link;
  • After installing, to ensure update the package running command python -m pip install cx_Oracle --upgrade

To find out if it worked you can run the following test:

# Use o diretório que você deszipou/instalou o instant client:
import os
os.chdir("C:\\Oracle\\instantclient_12_1")
import cx_Oracle

If running without error everything went well.

  • 1

    Thanks Max, it worked yes using my local base, however I passed the stringfrom my database that stay in other equipment, to access this base I use another client where tnsnames get in this way C:oracle product 10.2.0 client_1 network ADMIN more even passing the path it give error in Listener ORA-12505: TNS:Listener does not Currently know of SID Given in connect Descriptor, I will see with DBA if there is any particularity, but its solution was great, thank you and if you have any suggestions for this solution you can send me.

  • @Andressam How’s your string jdbc? It’s that line jdbc:oracle....

  • Max, I got through. It follows as it did for the remote server: #tests only the connection import os os.chdir("C: oracle product 10.2.0 client_1") import cx_Oracle con = cx_Oracle.connect('topm/[email protected]:1521/ tpdb.topm.local') ##(password/user@IP of the database:port/service_name) #executes query cur = con.cursor() cur.execute('select * from product Where idproduct=100') for result in cur: print (result[0]) cur.close() con.close()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.