B
B
Brenk2021-03-03 20:34:29
SQLite
Brenk, 2021-03-03 20:34:29

How to transfer variable values ​​from sqlite to telebot?

Hello, I just started writing code, so please do not throw slippers.
There is a code that pulls data from sql database and another code that sends messages via telebot.
It is not possible to implement the transfer of the value of variables from one file to another.

import sqlite3 as lite
import sys
con = lite.connect('database.db')

with con:
    cur = con.cursor()
    cur.execute("SELECT * FROM database")

    while True:
        row = cur.fetchone()
        if row is None:
            break
        print(row[0], row[1], row[2])


import telebot
from main import row

bot = telebot.TeleBot('token')


@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет!')


##@bot.message_handler(commands=['first'])
##def start_message(message):
##    bot.send_message(message.chat.id, row[3], row[4], row[5])

@bot.message_handler(commands=['two'])
def start_message(message):
        bot.send_message(message.chat.id, row[1], row[2], row[3])


bot.polling()


Initially, the code compiles normally, the bot starts up, but when the /two command is sent, this error pops up:
11 22 33
44 55 66
Traceback (most recent call last):
  File "D:\pythonProject2\bot.py", line 21, in <module>
    bot.polling()
  File "C:\Users\dmdbr\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 485, in polling
    self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
  File "C:\Users\dmdbr\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 544, in __threaded_polling
    raise e
  File "C:\Users\dmdbr\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 507, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\dmdbr\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 117, in raise_exceptions
    raise self.exception_info
  File "C:\Users\dmdbr\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 69, in run
    task(*args, **kwargs)
  File "D:\pythonProject2\bot.py", line 18, in start_message
    bot.send_message(message.chat.id, row[1], row[2], row[3])
TypeError: 'NoneType' object is not subscriptable

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question