Question

Error when following how to add authentication to your app with flask login tutorial

Posted May 13, 2020 114 views
Python

https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login

I had a lot of issue while doing this, I had searched a lot but couldn’t find anything. Please see my question

i was creating a server of login verification but after connecting it to the db, i was facing a lot of issue

my error -

[* Serving Flask app "project"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask_sqlalchemy\__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2020-05-13 17:34:35,237] ERROR in app: Exception on /signup [POST]
Traceback (most recent call last):
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: user

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\python\login\project\auth.py", line 26, in signup_post
    user = User.query.filter_by(email=email).first() # if this returns a user, then the email already exists in database
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\orm\query.py", line 3300, in first
    ret = list(self[0:1])
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\orm\query.py", line 3078, in __getitem__
    return list(res)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\orm\query.py", line 3405, in __iter__
    return self._execute_and_instances(context)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\orm\query.py", line 3430, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 984, in execute
    return meth(self, multiparams, params)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\sql\elements.py", line 293, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1103, in _execute_clauseelement
    distilled_params,
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1288, in _execute_context
    e, statement, parameters, cursor, context
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1482, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\util\compat.py", line 178, in raise_
    raise exception
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "c:\users\siddharth\appdata\local\programs\python\python37-32\lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user
[SQL: SELECT user.id AS user_id, user.email AS user_email, user.password AS user_password, user.name AS user_name
FROM user
WHERE user.email = ?
 LIMIT ? OFFSET ?]
[parameters: ('jxdn@gmail.com', 1, 0)]
(Background on this error at: http://sqlalche.me/e/e3q8)
127.0.0.1 - - [13/May/2020 17:34:35] "?[35m?[1mPOST /signup HTTP/1.1?[0m" 500 -]

here is full my code - https://github.com/shashwatagrawal123/login2

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hey @mailtoshashwata,

Your error here is that the user table doesn’t exist in the database.

sqlite3.OperationalError: no such table: user

Have you created the user model in your app and then generated the database using SQLAlchemy as described in these steps of the tutorial?:

https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login#creating-user-models

- Matt.

by Anthony Herbert
Allowing users to login to your app is one of the most common features you'll add to a web app you build. This article will cover how to add simple authentication to your Flask app with the Flask-Login package.
Submit an Answer