Forums

Internal server error - flask and sqlite3

Hi everybody,

Since yesterday I have an error I can not resolve... I want to do a web app using Flask and a database in sqlite3. So I have imported all the files that I need, and now I have something like that:

\mysite\
   flask_app.py
   data\
        myDataBase.db

In flask_app.py I just do a simple code but every time I try to execute a sql statement, I have an Error 500, Internal server error... My flask_app.py look just like that:

from flask import Flask
import sqlite3

app = Flask(__name__)


@app.route('/')
def hello_world():
    conn=sqlite3.connect('/home/Camille/mysite/data/myDataBase.db')
    cursor=conn.cursor()
    select="SELECT * FROM Repas"
    cursor.execute(select)
    test=cursor.fetchone()
    return test

    conn.close()
    cursor.close()

When I run the app with a console, everything work finem I can access my data base. But at <username>.pythonanywhere.com, I got internal server error. When I am not using the database I can access the web page.

If anyone know what I am doing wrong, please help me! Thanks a lot

What is in your error log when you get the error?

Hi, Thank you for your answer! I have something like that:

2016-07-14 03:21:22,538 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/​​user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
OperationalError: unable to open database file

So I though I have something wrong in the WSGI file but I didn't know what... However, I restart from the beginning, and I don't know why but now everything is working fine... yet I think I did the same things...

So it's working now but really I don't know why ... ^^'

Anyway, thank you for answering me!