How do I access an Oracle db without installing Oracle's client and cx_Oracle?
Asked Answered
Y

3

14

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.

I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.

The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:

DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')

Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?

Thanks in advance!

Yale answered 2/10, 2013 at 17:6 Comment(3)
For Perl to work there is an Oracle driver installed, and it talks to an Oracle client installed on that same machine, which then talks to the Oracle database. You need the client software on the machine you want to connect from, so it sounds like you're already configured and just need to install your Python drivers and code. Oracle is a very tight-fisted company, and control their drivers closely, so you'll need to use whatever means you can to talk to their client. If that means cx_oracle then you'll have to go that path.Inhibition
Thank you guys. I am researching calling perl DBI module from python now.Yale
Don't do that. It's a convoluted, and unworkable solution. Either write it in Perl, which would be my first path because I know Perl better than Python, or go with pure Python and load its needed drivers; Use whichever you know better.Inhibition
U
4

Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:

ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora

I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.

Upthrow answered 2/10, 2013 at 17:20 Comment(3)
This solves the problem of the user. But the question "How do I access an Oracle db without installing Oracle's client and cx_Oracle?" does not get answered.Ungrudging
If you are using Python's libraries, then you have no other choice. At least, not that I'm aware of. If you want to use Oracle DB, you play by their rules.Upthrow
if possible, I use PostgresSQL :-) in this case we found a work-around. We get a http API soon.Ungrudging
L
6

An excerpt from https://forum.omz-software.com/topic/184/oracle-database:

There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.

—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.

Lorrettalorri answered 2/10, 2013 at 17:14 Comment(2)
"... never will be" is there no coding hero out there to prove the opposite? It's possible - not easy but should doable.Ungrudging
Link to Pythonista forum was broken but Google saved the day!Ideology
U
4

Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:

ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora

I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.

Upthrow answered 2/10, 2013 at 17:20 Comment(3)
This solves the problem of the user. But the question "How do I access an Oracle db without installing Oracle's client and cx_Oracle?" does not get answered.Ungrudging
If you are using Python's libraries, then you have no other choice. At least, not that I'm aware of. If you want to use Oracle DB, you play by their rules.Upthrow
if possible, I use PostgresSQL :-) in this case we found a work-around. We get a http API soon.Ungrudging
R
0

if you don't want use cx_Oracle you should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

Rose answered 8/5, 2016 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.