I understand flask, I am faced with the task of implementing authorization not through a browser, but a client written in PyQt. In the flask framework, when authorizing a user who was registered and located in the SQLite database, there is a fragment of the code responsible for authorization, which I just rewrote:

@bp.route('/login', methods=('GET', 'POST')) def login(): if request.method == 'POST': username = request.get_json().get('username') password = request.get_json().get('password') #return username db = get_db() error = None user = db.execute( 'SELECT * FROM user WHERE username = ?', (username,) ).fetchone() #return user['id'] if user is None: error = 'Incorrect username.' elif not check_password_hash(user['password'], password): error = 'Incorrect password.' if error is None: #session.clear() #session['user_id'] = user['id'] return user['id'] #return user['username'] return error 

I can get the return value in the terminal if I return user ['username'] or user ['password'] - everything is fine with this, the request is normally executed with code 200, but I cannot return user ['id'] - I get a server error 500, which seems to me strange and incomprehensible, because there is an id in the database. Tell me, what could be the reason?

  • Need to stitch a name in the query 'SELECT * FROM user WHERE username = \'? \ ' - Alexander Chernin
  • Maybe you do not have an id column in the database? Because if user['password'] works, and user['id'] does not, then the password column is there, and id does not - suit
  • suit The fact of the matter is that there is an id INTEGER PRIMARY KEY AUTOINCREMENT column, but I can't get it ... - ZaurK
  • Alexander Chernin unfortunately, this does not help, if you overload it, you always get an error 500 - ZaurK
  • one
    Error 500 is necessarily accompanied by text in the error log, show the text of the error - andreymal

0