【问题标题】:Python records connecting to Oracle连接到 Oracle 的 Python 记录
【发布时间】:2017-03-11 12:01:07
【问题描述】:

我正在使用 Kenneth Ritz 的记录库连接到 Oracle。

db = records.Database('oracle://scott/tiger@localhost:1521/orcl')

但它总是抛出这个错误

DatabaseError: (cx_Oracle.DatabaseError) 
ORA-12545: Connect failed because target host 
or object does not exist.

但是,通过 SQL Plus 连接就可以了

sqlplus scott/tiger@localhost/orcl:1521

SQL*Plus: Release 12.1.0.1.0 Production on Sat Mar 11 17:29:19 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Last Successful login time: Sat Mar 11 2017 17:16:24 +05:30

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

有趣的观察

db = cx_Oracle.connect('scott/tiger@localhost:1521/orcl') **<--Works**

db.version
'12.1.0.1.0'

db = records.Database('oracle+cx_oracle://scott/tiger@localhost:1521/orcl')
doesn't work

知道我在这里做错了什么吗?

【问题讨论】:

    标签: python-3.x cx-oracle python-records


    【解决方案1】:

    records 依赖 sqlalchemy 来完成数据库的繁重工作。 请参考SQLAlchemydocumentation

    所以,URI 应该是这样的: oracle+cx_oracle://user:pass@localhost:1521/dbname

    【讨论】:

    • 感谢 Uku 的指点。尝试了这个 db = records.Database('oracle+cx_oracle://scott/tiger@localhost:1521/orcl') 但仍然没有乐趣
    • scott/tiger部分是什么意思?
    • 对不起,我的工作很糟糕,斯科特是用户名和密码是tiger.db = records.Database('oracle+cx_oracle://scott:tiger@localhost:1‌​521/orcl')跨度>
    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 2019-12-26
    • 1970-01-01
    • 2020-03-29
    • 2016-07-27
    • 2018-05-23
    • 2021-02-10
    • 2020-04-08
    相关资源
    最近更新 更多