-1

你们都被解雇了。撇开这件事不谈,我需要帮助来破译我在尝试使用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。此插件是否仅适用于版本 <=11 的 Oracle 数据库?

下面的复制/粘贴显示了来自其中一个数据库的横幅。

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 软件进行通信。

4

1 回答 1

1

为混乱道歉。错误消息中有一个错误。这只发生在非常旧版本的 Oracle 客户端库中。我刚刚在这里更正了这一点:https ://github.com/oracle/odpi/commit/d2fea3801286d054e18b0102e60a69907b7faa9a并将很快作为 cx_Oracle 7.1.1 的一部分发布。

因此,错误消息真正想告诉您的是,您需要拥有 11.2 或更高版本的 Oracle 客户端库,并且您的版本足够老,以至于它甚至不知道如何告诉您它是什么版本!所以很可能是 8i 或 9i 或 10g 的早期版本。对于那些旧版本,它们经常存储在 c:\Windows\system32 中,因此优先于您可能已安装的其他库。您可以通过将 PATH 环境变量设置为在开头包含 C:\app\client\corporateDrone\product\12.1.0\client_1\bin 来强制解决问题。如果这没有帮助,您可能必须找到并删除旧版本的 OCI.dll - 请记住,这样做会影响任何依赖它的软件!

官方文档可以在这里找到:https ://cx-oracle.readthedocs.io/en/latest/index.html 。有一个增强请求将这些包含在您注意到没有任何有用的内置帮助中。:-) 您可以在此处查看增强请求:https ://github.com/oracle/python-cx_Oracle/issues/175 。

希望能减轻你的困惑!

于 2019-02-14T23:00:53.900 回答