什么是DPY-6005:无法连接到数据库。连接失败了“ [errno 61]连接拒绝;平均有python-oracledB

发布于 2025-02-01 23:29:20 字数 744 浏览 1 评论 0原文

在带有Python 3.9.6 MacOS上使用Oracle的Python代码 python-oracledB驱动程序

import oracledb
import os

un = os.environ.get("PYTHON_USERNAME")
pw = os.environ.get("PYTHON_PASSWORD")
cs = "localhost/orclpdb1"

c = oracledb.connect(user=un, password=pw, dsn=cs)

:错误:

DPY-6005: cannot connect to database. Connection failed with "[Errno 61] Connection refused"

在Linux上,错误是:

DPY-6005: cannot connect to database. Connection failed with "[Errno 111] Connection refused"

这些是什么意思?

[更新:在Python-OracledB 1.0.1中,该错误用DPY-6005包装。在1.0.0中,仅显示了误差的下部python部分。]

On macOS with Python 3.9.6 the Python code using Oracle's python-oracledb driver:

import oracledb
import os

un = os.environ.get("PYTHON_USERNAME")
pw = os.environ.get("PYTHON_PASSWORD")
cs = "localhost/orclpdb1"

c = oracledb.connect(user=un, password=pw, dsn=cs)

gives the error:

DPY-6005: cannot connect to database. Connection failed with "[Errno 61] Connection refused"

on Linux the error is like:

DPY-6005: cannot connect to database. Connection failed with "[Errno 111] Connection refused"

What do these mean?

[Update: in python-oracledb 1.0.1 the error is wrapped with DPY-6005. In 1.0.0 just the lower level Python part of the error was shown.]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

捂风挽笑 2025-02-08 23:29:21
  • 一种情况是您使用的数据库端口(或默认端口1521)是
    不正确。找到正确的端口,然后使用它。例如,如果您的
    数据库侦听器在端口1530而不是默认端口1521上侦听,然后您可以尝试连接字符串:

      cs =“ localhost:1530/orclpdb1”
     
  • 确保主机名是正确的:您可能已连接到错误的机器。

  • One scenario is that the database port you used (or the default port 1521) is
    not correct. Find the correct port and use that instead. For example if your
    database listener is listening on port 1530 instead of the default port 1521, then you could try the connection string:

    cs = "localhost:1530/orclpdb1"
    
  • Make sure the hostname is correct: you may have connected to the wrong machine.

一笔一画续写前缘 2025-02-08 23:29:21

根据我的经验,“连接拒绝”通常意味着连接被积极否认,这可能意味着数据库受到防火墙的保护。如果您已经确认了主机名和端口是正确的,并且仍在遇到此错误,请确定是否存在防火墙,无论是在数据库服务器本身还是在网络上的其他位置上,并且创建了一个规则以完全允许访问或完全禁用它(假设这样做是安全的)。

In my experience, "connection refused" often means that the connection was actively denied, which could mean that the database is protected by a firewall. If you have already confirmed the hostname and port are correct and are still getting this error then determine if there is a firewall, either on the database server itself or elsewhere on the network, and have a rule created to allow access or disable it entirely (assuming it is safe to do so).

删除会话 2025-02-08 23:29:21

[打开Oracle NetManager并在XE节下进行]
[1]: https://i.sstatic.net/kef0h1kb.png

下面在Python和Oracle中创建通信:

语法:
varname = oracledB.connect(“用户名/密码@dns/serviceName”)

  DNS= hostname:Port number
  serviceid= XE
  username= system (By default)
  password= user_choice

我希望这对你们有帮助。

[Open Oracle Netmanager and go under the section xe]
[1]: https://i.sstatic.net/kEF0H1Kb.png

Remember this syntax below to create communication betwen python and oracle:

syntax:
varname= oracledb.connect("username/password@DNS/servicename")

  DNS= hostname:Port number
  serviceid= XE
  username= system (By default)
  password= user_choice

I hope this will help you guys.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文