为什么我不能在ubuntu 12.04中将python连接到firebird? [英] why can't I connect python to firebird in ubuntu 12.04?
问题描述
我也是python和firebird的新手,我的问题是我正在尝试将python程序连接到firebird中的数据库,我已经安装了firebird(当前位于/opt/firebird上),我已经创建了带有表的数据库(test.fdb)(在firebird中工作正常)
Hi I'm novice in python and firebird too, my problem is i'm trying to connect my python program to a database in firebird, I've installed firebird (is currently on /opt/firebird) I have created my database(test.fdb) with a table(it works fine in the 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中运行时会出现问题.
but when i'm trying to run in pydev occurs a problem.
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/文件/文档/drivers_documentation/python/fdb/getting-started.html
databse的当前位置在/tmp上,我正在使用从此处下载的fdb: https://pypi.python.org/pypi/fdb/并与pip一起安装,我也在pydev properties-> pydev pythonpath中使用并添加了fdb文件夹(到目前为止看起来很正常,没有错误),我的用户名是fernando并且密码是root,所以当我最终运行时,我收到以下错误消息:
current location of databse is on /tmp, I'm using fdb downloaded from here: https://pypi.python.org/pypi/fdb/ and installed with pip also I used in pydev properties->pydev pythonpath and added the folder of fdb (it seems normal so far with no errors),my username is fernando and password is root, so when I finally run I get this error message:
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)
如何解决?帮助和感谢.
How can this be fixed? help and thanks.
推荐答案
经Ubuntu 12.04.4
和fdb 1.4.1
检验,所有建议的语句类型均有效:
Checked with Ubuntu 12.04.4
and fdb 1.4.1
all suggested statement types are working:
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")
这篇关于为什么我不能在ubuntu 12.04中将python连接到firebird?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!