连接到Oracle的Python记录

问题描述:

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

db = records.Database('oracle://scott/[email protected]:1521/orcl') 

但它总是抛出此错误

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

但是通过SQL Plus中连接工作得很好

sqlplus scott/[email protected]/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/[email protected]:1521/orcl') **<--Works** 

db.version 
'12.1.0.1.0' 

db = records.Database('oracle+cx_oracle://scott/[email protected]:1521/orcl') 
doesn't work 

任何想法,我在做什么错这里 ?

INTE

records依赖sqlalchemy做数据库繁重工作。 请参阅SQLAlchemy的documentation

因此,URI应该是这样的: oracle+cx_oracle://user:[email protected]:1521/dbname

+0

感谢UKU的pointer.Tried该DB = records.Database(“ORACLE + cx_oracle://斯科特/老虎@localhost:1521/orcl')但仍然没有欢乐 – user3249433

+0

scott/tiger'部分的含义是什么? –

+0

对不起,我的这个作品scott是用户名和密码是tiger.db = records.Database('oracle + cx_oracle:// scott:tiger @ localhost:1 521/orcl') – user3249433