Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:50:01+00:00 2026-06-12T20:50:01+00:00

I’m trying to hook an existing sqlite3 db to a dashboard I’m building and

  • 0

I’m trying to hook an existing sqlite3 db to a dashboard I’m building and I’ve run into a problem that I can’t figure out how to resolve. I’ve been working on this by trying to piece together things from the Flask docs and other sources, so feel free to call me out on anything in here that looks a little odd. It probably is, and I just don’t know it 🙂

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

#config
DATABASE = '~/home/aaron/Dropbox/coding/webapp2/tmp/test.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'

app = Flask(__name__)
app.config.from_object(__name__)

def connect_db():
    return sqlite3.connect(app.config['DATABASE']) # LINE 17


@app.before_request
def before_request():
    g.db = connect_db() # LINE 22

@app.teardown_request
def teardown_request(exception):
    if hasattr(g, 'db'):
        g.db.close()

# App seems to error out before app.route and if __name__=='__main__' block
# Everything in my app.route is commented out

Complete error:

Traceback (most recent call last): File
“/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1701, in
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 before_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: unable to open database file

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 (most recent call last): File
“/usr/local/lib/python2.7/dist-packages/flask/app.py”, line 1701, in
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 before_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: unable to open database file

It seems that the problem is coming from this config line:

DATABASE = '~/home/aaron/Dropbox/coding/webapp2/tmp/test.db'

My questions:

1) Why is the OperationalError being thrown twice?

2) Why does each OperationalError call out lines 17 and 22 (commented in my code above), even though these are function definitions and and not function calls?

3) How do I resolve the error, given that this is a valid db with data at the path specified?

These are what I’m referencing:

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/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:50:02+00:00Added an answer on June 12, 2026 at 8:50 pm

    I think that the problem is the ~ character (valid in shell but not in Python), so you will probably need to write the full absolute path. I am not using Flask but I suggest to set up PROJECT_ROOT constant in your settings and then use relative paths:

    import os
    
    PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
    
    DATABASE = os.path.join(PROJECT_ROOT, 'tmp', 'test.db')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.