0

We are connecting to oracle from python using cx_oracle package. But the user_id, password and SID details are hardcoded in that. My question is, is there any way to create a Datasource kind of thing? Or how we will deploy such python script sin production?

The database is in a Linux box and python is installed in another Linux box(Weblogic server is also installed in this Linux box).

import cx_Oracle
con = cx_Oracle.connect('pythonhol/[email protected]/orcl')
print con.version

Expectation is :

Can we deploy python in a production instance? If yes how can we connect to the database by hiding the DB credentials?

1
  • What about storing the credentials in some file and reading the values from that file? Will that be acceptable for you? Commented Aug 21, 2019 at 12:12

1 Answer 1

1

Use some kind of 'external authentication', for example a wallet. See the cx_Oracle documentation https://cx-oracle.readthedocs.io/en/latest/user_guide/connection_handling.html#connecting-using-external-authentication

In summary:

  • create a wallet with mkstore which contains the username/password credentials.
  • copy the wallet to the machines that are running Python
  • make sure no bad people can access the wallet
  • configure Oracle Net files to point to the wallet
  • your scripts would connect like

    connection = cx_Oracle.connect(dsn="mynetalias", encoding="UTF-8")
    

    or

    pool = cx_Oracle.SessionPool(externalauth=True, homogeneous=False, dsn="mynetalias",
                     encoding="UTF-8")
    pool.acquire()
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.