使用python cx_Oracle使用LDAP连接到数据库 [英] Connect to DB using LDAP with python cx_Oracle

查看:85
本文介绍了使用python cx_Oracle使用LDAP连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组使用cx_Oracle连接到远程数据库的python脚本.如果多次使用此连接,这是一个很大的项目.此外,我生成了一个.exe文件,该文件已分发并且应尽可能独立.换句话说,如果我将.exe发送给您,则您应该能够运行它而无需进行任何额外的修改(我使用pyinstaller)

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 )

现在,我可以使用

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')

对象 con 在整个脚本中使用,始终作为熊猫 read_sql 函数调用的连接参数.

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

一切正常,但我的数据库管理员要求使用ldap设置此连接.我已经四处搜寻,而我找到的唯一解决方案是在客户端的某个位置创建文件...没有其他方法吗?我不能直接在脚本上传递ldap配置吗?

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?

推荐答案

在客户端上需要正确配置的SQLNet.ORA和LDAP.ORA文件,才能使用LDAP作为TNSNAMES存储库.您可以在脚本中创建SQLNet.ORA和LDAP.ORA,并使用cx_oracle.init_oracle_client(lib_dir ="..配置文件路径..")加载这些配置文件.

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..").

这篇关于使用python cx_Oracle使用LDAP连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆