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

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

问题描述

我有一组使用 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 在脚本中使用,始终作为 pandas 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="..path to configuration files..") 加载这些配置文件.

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

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

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