Connect to DB using LDAP with python cx_Oracle

北战南征 提交于 2021-02-07 10:52:52

问题


I have a set of python scripts that use cx_Oracle to connect to a remote DB. This is a large project, were this connections are used several times. Additionally, I produce an .exe file that is distributed and should be as self-contained as possible. In other words, if I send you the .exe, you should be able to run it without any extra tinkering (I use pyinstaller )

Right now, I get a connection using

ip = 'myhost.example.pt'
port = 1521
SID = 'MYDB_PRD.EXAMPLE.PT'
dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)
con = cx_Oracle.connect(username_bd, password_bd, dsn_tns, encoding='UTF-8')

The object con is used thorough the script, always as the connection argument for a pandas read_sql function call.

Everything is ok, except that my DB Admins are asking to setup this connection using ldap. I've search around, and the only solution I find to do it involves creating a file somewhere on the client... Is there no other way? Can't I pass the ldap configurations directly on the script?


回答1:


Properly configured SQLNet.ORA and LDAP.ORA files are required on the client to use LDAP as a TNSNAMES repository. You can create both SQLNet.ORA and LDAP.ORA in your script and load these configuration files using cx_oracle.init_oracle_client(lib_dir="..path to configuration files..").



来源:https://stackoverflow.com/questions/64426038/connect-to-db-using-ldap-with-python-cx-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!