【问题标题】:Confusion Deciphering Error Code Python Module To Connect To Oracle (cx_Oracle)混淆解密错误代码 Python 模块以连接到 Oracle (cx_Oracle)
【发布时间】: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&gt;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&gt;

标签: oracle python-2.7 pluggable-database


【解决方案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

希望能减轻你的困惑!

【讨论】:

  • 哇,太棒了!谢谢你提供答案。很高兴帮助调试您的软件。 :) 我认为我的计算机上确实有多个版本的 Oracle DBMS。另外,我很遗憾地说,客户端库/箱的路径实际上是我的 PATH 中的第三项。我将不得不挖掘我的 PATH 和 System32,看看是否可以在某个地方找到另一个 OCI.dll。再次感谢您在这件事上的帮助。
  • 请查看我帖子的更新。我现在收到一个新错误。 :/ 我不确定我是否安装了 32 位,或者使用该模块是否需要 32 位或 64 位。请帮忙。感谢您阅读此人。
  • 该错误意味着您安装的 DLL(Oracle 客户端)是 64 位的。您需要确保 Python 和您的 Oracle 客户端 64位或 32位。你不能混搭!
  • 是的,我想就是这样。我有 32 位 python,所以我需要一个 32 位 DLL。我现在有这个模块工作。再次感谢您的专家帮助。
  • cx_Oracle 7.1.1 已被released 纠正错误消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2016-06-01
  • 2020-02-06
  • 2019-03-30
  • 1970-01-01
  • 2019-10-09
相关资源
最近更新 更多