Answer the question
In order to leave comments, you need to log in
Python does not see the Sqlite table, what should I do?
According to the video tutorial, HowdyHo tried to connect the database to the telegram bot, did everything as he did in the video, but the error "Error no such table: users"
pops up. I go into the tables and see the "users" table with my own eyes, but the python does not see.
What to do with it?
import sqlite3
import telebot
import random
from telebot import types
try:
conn = sqlite3.connect("Database.db")
cursor = conn.cursor()
cursor.execute("INSERT OR IGNORE INTO 'users' ('user_id') VALUES (?)", (1000,))
users = cursor.execute("SELECT * FROM 'users'")
print(users.fetchall())
conn.commit()
except sqlite3.Error as error:
print("Error", error)
finally:
if(conn):
conn.close()
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
bot.send_message(message.from_user.id, f"Привет, {message.from_user.first_name}")
markup = types.InlineKeyboardMarkup()
button1 = types.InlineKeyboardButton('МОСКВА', callback_data='1')
button2 = types.InlineKeyboardButton('ЛЮБЕРЦЫ', callback_data='2')
button3 = types.InlineKeyboardButton('КОРОЛЕВ', callback_data='3')
markup.row(button1, button2)
markup.row(button3)
bot.send_message(message.from_user.id, f"Выберите город", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):
bot.answer_callback_query(callback_query_id=call.id)
answer = ''
if call.data == '1':
markup = types.InlineKeyboardMarkup()
button23 = types.InlineKeyboardButton('Набор наклеек v1', callback_data='23')
button24 = types.InlineKeyboardButton('Набор наклеек v2', callback_data='24')
button25 = types.InlineKeyboardButton('Набор наклеек v3', callback_data='25')
markup.row(button23)
markup.row(button24)
markup.row(button25)
bot.send_message(call.message.chat.id, f"Ваше предпочтение", reply_markup=markup)
bot.answer_callback_query(callback_query_id=call.id)
answer = ''
bot.polling(none_stop=True, interval=0)
Answer the question
In order to leave comments, you need to log in
video tutorial HowdyHo
import sys
import pathlib
script_path = pathlib.Path(sys.argv[0]).parent # абсолютный путь до каталога, где лежит скрипт
conn = sqlite3.connect(script_path / "Database.db") # формируем абсолютный путь до файла базы
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question