A
A
Alexander2019-11-03 13:06:11
Python
Alexander, 2019-11-03 13:06:11

Error when working with a database in Python?

with sqlite3.connect(config.db_name) as conn:
                cursor = conn.cursor()
                stmt = "SELECT token FROM users WHERE username=:login"
                args = {'login': call.message.from_user.username}
                cursor.execute(stmt, args)
                row = cursor.fetchone()
                token = row[0]['token']

Can't connect to DB via Python for Telegram bot, what's wrong?
Mistake:
2019-11-03T09:32:54.785202+00:00 app[bot.1]:     token = row[0]['token']
2019-11-03T09:32:54.78522+00:00 app[bot.1]: TypeError: 'NoneType' object is not subscriptable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Ternick, 2019-11-03
@Ternick

Such an error is obtained like this:
In general, I did not work with sqlite3, but if you give me your database, I will help.
And so I can say that it does not find anything at your request, which means it shoves None, and you are trying to get data from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question