I am trying to connect an existing sqlite3 db to the panel that I am creating and I am having a problem and cannot figure out how to solve it. I am working on this trying to combine things from Flask docs and other sources, so feel free to call me on something here that looks a little weird. Perhaps this is so, and I just donβt know :)
the code:
from __future__ import with_statement from contextlib import closing from flask import Flask, render_template, request, session, g, redirect, url_for, abort, flash import sqlite3
Full error:
Traceback (last last call): File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, to call return self.wsgi_app (environ, start_response) File "/ usr / local / lib / python2.7 / dist-packages / flask / app.py ", line 1689, in wsgi_app response = self.make_response (self.handle_exception (e)) File" /usr/local/lib/python2.7/ dist-packages / flask / app.py ", line 1687, in wsgi_app response = self.full_dispatch_request () File" /usr/local/lib/python2.7/dist-packages/flask/app.py ", line 1360, in full_dispatch_request rv = self.handle_user_exception (e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1356, in full_dispatch_request rv = self.preprocess_request () File "/ usr /local/lib/python2.7/dist-packages/flask/app.py ", line 1539, in preprocess_request rv = func () File" /home/aaron/Dropbox/coding/webapp2/control.py ", line 22 , in be fore_request g.db = connect_db () File "/home/aaron/Dropbox/coding/webapp2/control.py", line 17, in connect_db return sqlite3.connect (app.config ['DATABASE']) OperationalError: cannot open file Database
127.0.0.1 - - [13 / Oct / 2012 13:55:48] "GET /? Debugger = yes & cmd = resource & f = style.css HTTP / 1.1" 200 - 127.0.0.1 - - [13 / Oct / 2012 13:55 : 48] "GET /? Debugger = yes & cmd = resource & f = jquery.js HTTP / 1.1" 200 - 127.0.0.1 - - [13 / Oct / 2012 13:55:48] "GET /? Debugger = yes & cmd = resource & f = debugger .js HTTP / 1.1 "200 - 127.0.0.1 - - [13 / Oct / 2012 13:55:48]" GET /? debugger = yes & cmd = resource & f = console.png HTTP / 1.1 "200 - 127.0.0.1 - - [ 13 / Oct / 2012 13:55:48] "GET /? Debugger = yes & cmd = resource & f = source.png HTTP / 1.1" 200 - 127.0.0.1 - - [13 / Oct / 2012 13:55:49] "GET / favicon.ico http / 1.1 "500 -
Traceback (last last call): File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, to call return self.wsgi_app (environ, start_response) File "/ usr / local / lib / python2.7 / dist-packages / flask / app.py ", line 1689, in wsgi_app response = self.make_response (self.handle_exception (e)) File" /usr/local/lib/python2.7/ dist-packages / flask / app.py ", line 1687, in wsgi_app response = self.full_dispatch_request () File" /usr/local/lib/python2.7/dist-packages/flask/app.py ", line 1360, in full_dispatch_request rv = self.handle_user_exception (e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1356, in full_dispatch_request rv = self.preprocess_request () File "/ usr /local/lib/python2.7/dist-packages/flask/app.py ", line 1539, in preprocess_request rv = func () File" /home/aaron/Dropbox/coding/webapp2/control.py ", line 22 , in be fore_request g.db = connect_db () File "/home/aaron/Dropbox/coding/webapp2/control.py", line 17, in connect_db return sqlite3.connect (app.config ['DATABASE']) OperationalError: cannot open file Database
The problem seems to come from this configuration line:
DATABASE = '~/home/aaron/Dropbox/coding/webapp2/tmp/test.db'
My questions:
1) Why is the OperationalError statement repeated twice?
2) Why does each OperationalError raise lines 17 and 22 (commented out in my code above), although these are function definitions and not function calls?
3) How to fix the error, given that this is a valid db with data on the specified path?
This is what I refer to:
http://flask.pocoo.org/docs/tutorial/dbcon/#tutorial-dbcon
http://flask.pocoo.org/docs/tutorial/views/#tutorial-views
http://flask.pocoo.org/docs/patterns/sqlite3/