Baseado na documentação da biblioteca do Firebird em python FDB
A database connection is typically established with code such as this:
import fdb
# The server is named 'bison'; the database file is at '/temp/test.db'.
con = fdb.connect(dsn='bison:/temp/test.db', user='sysdba', password='pass')
# Or, equivalently:
con = fdb.connect(
host='bison', database='/temp/test.db',
user='sysdba', password='pass'
)
No seu código tem alguns pontos importantes:
- O parametro
dns
na função de conectar pode estar errada.
- Verifique se esse caminho do banco de dados realmente existe, inclusive esse arquivo
- Na penultima linha o correto seria
if __name__ == '__main__'
.
Pelo que vi na documentação, é possível passar manualmente todos os parâmetros, incluindo host
e database
. Vamos fazer o teste para garantir. Qualquer complemento, adicione no comentário
from flask import Flask, render_template
import fdb
app = Flask(name)
DATABASE = "/ecosis/dados/mundial/ecodados.eco"
USER = "sysdba"
PASSWORD = "masterkey"
HOST = "localhost"
PORT = 3050
@app.route("/")
def index():
conn = fdb.connect(
dsn=HOST,
database=DATABASE,
host = host,
user=USER,
password=PASSWORD,
port=PORT
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM tvenpedido")
data = cursor.fetchall()
conn.close()
return render_template("index.html", data=data)
if __name__ == "__main__":
app.run(debug=True)
Outro ponto, apenas para garantir, você fez a instalação da biblioteca do FDB corretamente?
Qualquer dúvida veja aqui: Getting Started — FDB 2.0 documentation
FDB is written as pure-Python module (requires Python 2.7 or 3.4+) on top of Firebird client library (fbclient.so/dll) using ctypes, so make sure you have Firebird client properly installed before you try to install FDB, otherwise the installation will fail.
FDB supports Firebird version 2.0 and higher.
FDB is distributed as setuptools package and the preferred installation method is via pip tool.