Ввод переменной в таблицу SQlite3
import telebot
import sqlite3
import config
from telebot import types
bot = telebot.TeleBot(config.token)
conn = sqlite3.connect(r'dbp.ptyy.db')
cursor = conn.cursor()
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
btn1 = types.KeyboardButton('Я хочу зарегистроваться')
markup.add(btn1)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message,"Добро пожаловать",reply_markup=markup)
us_id = message.from_user.id
cursor.execute('INSERT INTO test VALUES(?)',us_id)
conn.commit()
@bot.message_handler(content_types=['text'])
def reg(message):
if message.text == "Я хочу зарегистроваться":
bot.reply_to(message,"Введи свое имя")
user_name = message.text
cursor.execute('INSERT INTO test (user_name) VALUES (?)', (user_name))
conn.commit()
bot.send_message(message.chat.id,"Введи фамилию")
bot.polling(none_stop=True)
Хотел ввести ID пользователя Telegram в базу данных но выскакивает ошибка
line 18, in send_welcome cursor.execute('INSERT INTO test VALUES(?)',us_id) sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 13948 and this is thread id 8528.