【发布时间】:2019-07-08 21:10:04
【问题描述】:
你们都被解雇了。撇开这件事不谈,我需要帮助来破译我在尝试使用 cx_Oracle 模块连接到 Oracle 数据库时看到的错误代码。由于一些不负责任和愚蠢的原因,我使用 Python2.7 而不是 Python3000。我看到的错误信息如下(当然是复制/粘贴):
>>> connection = cx_Oracle.connect('user', 'password123', 'db1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1050: Oracle Client library is at version 11.2 but
must be at version 0.0 or higher
>>>
我通过这个命令在模块内部发现了一些糟糕的文档:help('cx_Oracle.connect')
此命令产生以下页面,第一页仅为简洁起见:
Help on class Connection in cx_Oracle:
cx_Oracle.connect = class Connection(__builtin__.object)
| Methods defined here:
|
| __enter__(...)
|
| __exit__(...)
|
| __init__(...)
| x.__init__(...) initializes x; see help(type(x)) for signature
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| begin(...)
|
| cancel(...)
|
| changepassword(...)
|
| close(...)
|
| commit(...)
|
| createlob(...)
|
| cursor(...)
|
| deq(...)
|
| deqoptions(...)
|
| enq(...)
|
| enqoptions(...)
|
| getSodaDatabase(...)
|
| gettype(...)
|
| msgproperties(...)
|
| ping(...)
|
| prepare(...)
-- More --
我在以下网页找到了关于如何使用 API 的更好解释:https://dzone.com/articles/python-code-can-connect-oracle
有人想知道为什么模块作者没有像网页作者那样写出清晰的说明,例如:
# Connect using the ordered parameters user, password and SID.
dbconn = cx_Oracle.connect('user', 'password' ,'SID')
我还在以下 URL 找到了更多文档:https://developer.oracle.com/databases/database-for-python-developers-1
本文档可能来自另一个时代,用于 Oracle 数据库的早期实现。
据我所知,此插件仅适用于 11g 的 Oracle 数据库,可能更低。我使用的可插拔数据库和普通数据库,没有更好的术语,都是 12c。此插件是否仅适用于版本
下面的复制/粘贴显示来自其中一个数据库的横幅。
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing op
ions
尊敬的,
一个笨蛋
----------更新------------- ----------------------------------------
我听取了对这个软件项目的建议很有帮助的开发人员,现在我收到了一个新错误。我从关于 Oracle DB 版本 11 的路径中删除了一些我认为不需要的东西,并看到一条新的错误消息:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> connection = cx_Oracle.connect('user', 'password', 'oracledb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1047: 32-bit Oracle Client library cannot be loaded
: "C:\app\client\corpDrone\product\12.1.0\client_1\bin\oci.dll is not the correct a
rchitecture". See https://oracle.github.io/odpi/doc/installation.html#windows fo
r help
我想通了。我按照上面错误消息中的链接,然后下载了 32 位即时客户端精简版软件,并将其作为我路径中的第一件事。然后我按照手册将 tnsnames.ora 文件放在从 TNS_NAMES 环境变量引用的第二个路径上。 :) 希望这对以后有些抱歉的混蛋有所帮助。 :D
一个更简单的选择是重新安装您的 Python 实现。就我而言,我需要 64 位 Python 才能与 64 位 Oracle DBMS 软件进行通信。
【问题讨论】:
-
一些不必要的事情可能不需要说,包括所有的调查。你检查安装说明了吗?您使用的是什么版本的 Oracle 客户端库?
-
我没有检查安装说明,我不确定所说的“客户端库”在哪里。
-
@ChristopherJones 我使用
pip工具安装了cx_Oracle模块。 -
我确实使用以下命令升级了我的 cx_Oracle 模块版本:
C:\Users\corporateDrone\Desktop>python -m pip install cx_Oracle --upgrade DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Requirement already up-to-date: cx_Oracle in c:\python27\lib\site-packages (7.1. 0) C:\Users\corporateDrone\Desktop>
标签: oracle python-2.7 pluggable-database