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

标签 python firebird

嗨,我也是 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/

相关文章:

sql - 四舍五入到下一个十分位,减去 0.02

c# - 带日期时间的 Firebird 数据库查询

python - 检查使用 twistd 启动的 Twisted Server 是否成功启动

python - 使用 python 3.5 和 urllib 禁用 SSL 身份验证

delphi - FireDAC TFDConnection.GetTableNames 不适用于具有受信任身份验证的 Firebird

python - 我无法从 Python 连接到 FDB 数据库

Python 将 csv 数据导出到文件中

python - 来自 SUDS.client 的未知字符串格式(汤?)的可能解析器

python - 如何对凹面多边形进行三角剖分?

Firebird 2.5 CHARACTER SET WIN1252 未安装