简体   繁体   中英

is cx_Oracle in Flask-SQLAlchemy can be accessed only through oracle-instant Client?

My oracle database[OracleSlim] is up and running in Docker container and i created a user, table inside container. it's running on 0.0.0.0:1521 . Do i need 'oracle instant client installed' to make cx_oracle working?

I tried this 'sqlplus administrator/Welcome121@ORCLCDB' connection string inside a container. it's working.

from sqlalchemy import create_engine
import cx_Oracle
engine=create_engine('oracle://username:password@hostname:port/sid')

Error:

cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help

A sucessfull oracle connectivity in my flask-Sqlalchemy's Engine object. New ORM or Packages for connecting oracle are welcome. Note: I have not installed oracle instant client on my local but have installed it in my container.

UPDATED

Now i have Oracle Running on my Docker Container.And I am going to connect those from Python cx_Oracle in Local. with a method below,

import cx_Oracle
constr = 'system/oracle@//172.17.0.2:1521/orcl.localdomain'
conn = cx_Oracle.connect(constr)

is it possible to connect with a container that is running on localhost:1521 with a help of python cx_Oracle or Flask-SQLAlchemy?

You do need oracle client libraries:

This comes from cx_Oracle docs:

To use cx_Oracle 7 with Python and Oracle Database you need: Python 2.7 or 3.5 and higher. Older versions of cx_Oracle may work with older versions of Python. Oracle client libraries. These can be from the free Oracle Instant Client, or those included in Oracle Database if Python is on the same machine as the database. Oracle client libraries versions 18, 12, and 11.2 are supported on Linux, Windows and macOS. Users have also reported success with other platforms. An Oracle Database. Oracle's standard client-server version interoperability allows cx_Oracle to connect to both older and newer databases.

If sqlplus administrator/Welcome121@ORCLCDB' is working then you must already have Oracle Client libraries available because both sqlplus and cx_Oracle require the same set of Oracle libraries. Verify that sqlplus can really query your database.

Check that the SQL*Plus version is 11.2 or higher. Then work out what the difference is between your configuration for sqlplus and python. Configure the environment variables needed for cx_Oracle the same was as for sqlplus. If you have a full Oracle Client or Oracle DB installed, you can set the environment before running python with source /usr/local/bin/oraenv . If you have the old Oracle XE 11.2 the command is source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh

If you don't have Oracle Client libraries then install them following https://cx-oracle.readthedocs.io/en/latest/installation.html#installing-cx-oracle-on-linux I recommend using ldconfig to set the library search path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM