Python-Бот телеграм с бд, ошибка TypeError: 'int' object is not callable
Сначала код работал стабильно, потом когда начал вставлять данный в бд из кода, начались проблемы. Вот код:
import pymysql
import telebot
import time
from config import host, user, password, db_name
from telebot import types, apihelper
bot = telebot.TeleBot(токен)
try:
connection = pymysql.connect(
host=host,
port=3306,
user=user,
password=password,
database=db_name,
cursorclass=pymysql.cursors.DictCursor
)
print('Connect')
except Exception as ex:
print('Not connected')
@bot.message_handler(commands=['start'])
def start_command(message):
user_id = message.from_user.id
markup = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
regbtn = types.KeyboardButton('Зарегистрироваться')
markup.add(regbtn)
bot.send_message(user_id, "Привет! Я - бот бухгалтер. Для начала тебе надо
зарегистрироваться. Нажми на кнопку ниже, чтобы это сделать", reply_markup=markup)
@bot.message_handler(content_types=['text'])
def registration(message):
word1 = message.from_user.first_name
user_id = message.from_user.id
if message.text == 'Зарегистрироваться':
num = 0
temp = bot.send_message(user_id, 'Введи свой начальный капитал(в рублях, целым числом)')
bot.register_next_step_handler(temp, num)
with connection.cursor() as cursor:
info1 = "INSERT info (name, date) VALUES (%s, NOW())"
cursor.execute(info1, word1)
values1 = "INSERT records (value, operation) VALUES (%s, 1)"
cursor.execute(values1, num)
connection.commit()
bot.polling(none_stop=True, interval=0)
если убрать эту часть кода:
values1 = "INSERT records (value, operation) VALUES (%s, 1)"
cursor.execute(values1, num)
connection.commit()
и все её компоненты, бот спокойно работает(конечно, с чего бы ему не работать. Он в таком случае ничего и не делает)
В общем, помогите плиз, не знаю как это пофиксить
Трасса ошибки:
Traceback (most recent call last):
File "D:/PyProgects/main.py", line 50, in <module>
bot.polling(none_stop=True, interval=0)
File "D:\PyProgects\venv\lib\site-packages\telebot\__init__.py", line 637, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "D:\PyProgects\venv\lib\site-packages\telebot\__init__.py", line 699, in __threaded_polling
raise e
File "D:\PyProgects\venv\lib\site-packages\telebot\__init__.py", line 659, in __threaded_polling
self.worker_pool.raise_exceptions()
File "D:\PyProgects\venv\lib\site-packages\telebot\util.py", line 130, in raise_exceptions
raise self.exception_info
File "D:\PyProgects\venv\lib\site-packages\telebot\util.py", line 82, in run
task(*args, **kwargs)
TypeError: 'int' object is not callable
Ответы (1 шт):
Автор решения: CrazyElf
→ Ссылка
num = 0
^^^^^^^
temp = bot.send_message(user_id, 'Введи свой начальный капитал(в рублях, целым числом)')
bot.register_next_step_handler(temp, num)
^^^
Второй параметр, передаваемый в register_next_step_handler - это функция, которую нужно выполнять следующей. А вы ей число num передаёте, поэтому такая ошибка выходит.