Connect to DB using LDAP with python cx_Oracle(使用 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 连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 LDAP 和 python cx_Oracle 连接到数据库
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
