A few days ago, I had to write a Python script that would enable us to write some data to an Oracle database. At first, I had no idea how to start. So, I downloaded a simple example script that I tried to run. The script was found via Google. This script looked like:
import cx_Oracle con = cx_Oracle.connect('C##SCOTT/binvegni@localhost/orcl') print con.version con.close()
I decided to run this script. This provided a clear error message. The error message looked like:
Traceback (most recent call last): File "D:\Users\tmaanen\CloudStation\Drive\Erste\Midas\ora.py", line 1, inimport cx_Oracle ImportError: No module named cx_Oracle
I then looked in Google how to solve this error message. I then downloaded the module. A subsequent attempt gave another error message. Again a clear error message.
Traceback (most recent call last): File "D:\Users\tmaanen\CloudStation\Drive\Erste\Midas\ora.py", line 2, incon = cx_Oracle.connect('scott/binvegni@127.0.0.1/orcl') DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
It looked like the servicename was wrong. The correct servicename could be found with the command tnsping. Modifying the script and running it again provided an almost trival error message.
Traceback (most recent call last): File "D:\Users\tmaanen\CloudStation\Drive\Erste\Midas\ora.py", line 2, incon = cx_Oracle.connect('scott/binvegni@localhost/orcl.corp.capgemini.com') DatabaseError: ORA-01017: invalid username/password; logon denied
Oops: wrong userid. Sorry. The last attempt was succesfull:
12.2.0.1.0
Al in all, it took me less than half an hour to get this going. I was really impressed with the excellent support from the open source.