gpt4 book ai didi

python - 为什么我无法在 ubuntu 12.04 中将 python 连接到 firebird?

转载 作者:太空宇宙 更新时间:2023-11-03 18:50:23 27 4
gpt4 key购买 nike

嗨,我也是 python 和 firebird 的新手,我的问题是我正在尝试将我的 python 程序连接到 firebird 中的数据库,我已经安装了 firebird (当前位于/opt/firebird 上)我已经创建了我的带有表的数据库(test.fdb)(在firebird中工作正常)

create table languages
(
name varchar(20),
year_released integer
);

insert into languages (name, year_released) values ('C', 1972);
insert into languages (name, year_released) values ('Python', 1991);

但是当我尝试在 pydev 中运行时出现问题。

import fdb

con = fdb.connect(dsn="/tmp/test.fdb", user="fernando", password="root")

# Create a Cursor object that operates in the context of Connection con:
cur = con.cursor()

# Execute the SELECT statement:
cur.execute("select * from languages")

# Retrieve all rows as a sequence and print that sequence:
print cur.fetchall()

http://www.firebirdsql.org/file/documentation/drivers_documentation/python/fdb/getting-started.html

数据库的当前位置在/tmp,我使用的是从这里下载的fdb:https://pypi.python.org/pypi/fdb/并与 pip 一起安装,我也在 pydev properties->pydev pythonpath 中使用并添加了 fdb 文件夹(到目前为止似乎正常,没有错误),我的用户名是 fernando,密码是 root,所以当我最终运行时,我收到此错误消息:

Traceback (most recent call last):
File "/home/elfstone/Documents/workspace/NuevosPython/fire.py", line 3, in <module>
con = fdb.connect(dsn="/tmp/test.fdb", user="fernando", password="root")
File "/home/elfstone/Downloads/fdb-1.4/fdb/fbcore.py", line 693, in connect
"Error while connecting to database:")
fdb.fbcore.DatabaseError: ('Error while connecting to database:\n- SQLCODE: -902\n- Unable to complete network request to host "localhost".\n- Failed to establish a connection.', -902, 335544721)

如何解决这个问题?帮助和感谢。

最佳答案

检查了 Ubuntu 12.04.4fdb 1.4.1 所有建议的语句类型都有效:

fdb.connect(dsn="/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")
fdb.connect(host="localhost", database="/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")
fdb.connect(dsn="localhost:/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")

关于python - 为什么我无法在 ubuntu 12.04 中将 python 连接到 firebird?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18504399/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com