def next_create_subtask_step(message):
name_task = message.text
sqlb = "SELECT id FROM tasks WHERE id = 15"
print(sqlb)
db.execute(sqlb)
task_id = db.fetchone()
print(task_id)
task = task_id[0]
data_subtask['id_task'] = task
msg = bot.reply_to(message, 'Придумайте название подзадачи')
bot.register_next_step_handler(msg, request_subtask)
SELECT id FROM tasks WHERE id = 15
None
Traceback (most recent call last):
File "c:\Users\Emaq-\Desktop\inTaskBot\bot.py", line 711, in <module>
bot.polling(none_stop=True)
File "C:\Users\Emaq-\Desktop\inTaskBot\env\Lib\site-packages\telebot\__init__.py", line 1043, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "C:\Users\Emaq-\Desktop\inTaskBot\env\Lib\site-packages\telebot\__init__.py", line 1118, in __threaded_polling
raise e
File "C:\Users\Emaq-\Desktop\inTaskBot\env\Lib\site-packages\telebot\__init__.py", line 1074, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\Emaq-\Desktop\inTaskBot\env\Lib\site-packages\telebot\util.py", line 147, in raise_exceptions
raise self.exception_info
File "C:\Users\Emaq-\Desktop\inTaskBot\env\Lib\site-packages\telebot\util.py", line 90, in run
task(*args, **kwargs)
File "c:\Users\Emaq-\Desktop\inTaskBot\bot.py", line 469, in next_create_subtask_step
task = task_id[0]
~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable
def next_create_subtask_step(message):
name_task = message.text
sqlb = "SELECT id FROM tasks WHERE id = '{}'".format(name_task)
print(sqlb)
db.execute(sqlb)
task_id = db.fetchone()
print(task_id)
task = task_id[0]
data_subtask['id_task'] = task
msg = bot.reply_to(message, 'Придумайте название подзадачи')
bot.register_next_step_handler(msg, request_subtask)
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True)
username = '@' + message.from_user.username
sql = "SELECT id FROM users WHERE tg_name = '{}'".format(username)
db.execute(sql)
user_id = db.fetchone()
user = user_id[0]
url = 'http://intask/public/api/tasks/{}'.format(user)
result = requests.get(url)
tasks = result.json()
for task in tasks['tasks']:
markup.add(task['name'])
msg = bot.reply_to(message, 'Выберите задачу', reply_markup=markup)
bot.register_next_step_handler(msg, next_create_subtask_step)
SELECT id FROM tasks WHERE name = 'Хабр'
None
Проблема решена с помощью API - теперь все хорошо отрабатывает (хотя вопрос, почему не работало при прежнем подходе все еще остается загадкой)