2017-03-11 38 views
0

我正在使用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

回答

0

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