M
M
motya882020-07-09 11:42:23
Python
motya88, 2020-07-09 11:42:23

How to solve problem with telegram bot?

Good afternoon!
Wrote a bot with which about 50 people work.
In the course of work, errors such as the following often occur:

2020-07-09 07:30:48,431 (util.py:65 WorkerThread4) ERROR - TeleBot: "TypeError occurred, args=("getphoto_left_c() missing 1 required positional argument: 'random_code'",)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/telebot/util.py", line 59, in run
    task(*args, **kwargs)
TypeError: getphoto_left_c() missing 1 required positional argument: 'random_code'

Does the error occur due to concurrent use by multiple users?
How can I correct and get rid of the error? I tried to find norms and norms on how to rewrite to synchronous, but I didn’t really find any information.
Please, help.
bot piece below:
@bot.message_handler(content_types= ["photo"])

def getphoto_left_c(message, random_code):
    if message.content_type != 'photo':
        msg_r = bot.reply_to(message, 'Сделайте фотограцию короба слева')
        bot.register_next_step_handler(msg_r, getphoto_left_c, random_code)
        return
    bot.forward_message(TO_CHAT_ID, message.chat.id, message.message_id)
    bot.send_message(TO_CHAT_ID, 'Фотография короба слева. КОД: ' + str(random_code))
    msg = bot.send_message(message.chat.id,
                              'ШАГ 2 из 2' + "\n"  +'Сделайте фотографию работающего короба справа, чтобы было видно изображение на коробе.')
    bot.register_next_step_handler(msg, getphoto_right_c, random_code)

def getphoto_right_c(message, random_code):
    if message.content_type != 'photo':
        msg_r = bot.reply_to(message, 'ЖСделайте фотограцию короба справа')
        bot.register_next_step_handler(msg_r, getphoto_right_c, random_code)
        return

    bot.forward_message(TO_CHAT_ID, message.chat.id, message.message_id)
    bot.send_message(TO_CHAT_ID, 'Фотография короба слева. КОД: ' + str(random_code))
    ts = message.date
    datetime_end = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
    bot.send_message(message.chat.id,
                              'Спасибо за ответы.')
    taxi_bd.update_datetime_end(datetime_end,random_code)


@bot.message_handler(content_types=["text"])

def all(message):
    idm = message.chat.id
    user_check = taxi_bd.check_user(idm)

    
    if message.text == ' Фото после заказа' and user_check is not None:
        print('Сценарий C: ' + message.text)
        scenario = 'Фото после заказа'
        idm = message.chat.id
        ts = message.date
        datetime_start = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
        first_name = message.chat.first_name
        user_name = message.chat.username
        last_name = message.chat.last_name
        random_code = random.randint(1, 99999999)

        msg = bot.send_message(message.chat.id,
                               'ШАГ 1 из 2' + "\n"  +'Сделайте фотографию работающего короба слева, чтобы было видно изображение на коробе.')
        taxi_bd.insert_taxi_anketa(random_code, idm, first_name, user_name, last_name, scenario, datetime_start)

        bot.register_next_step_handler(msg, getphoto_left_c, random_code)

    

if __name__ == '__main__':
    bot.polling(none_stop=True, timeout=60)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-07-09
@motya88

Get the decorator out of here

@bot.message_handler(content_types= ["photo"])
def getphoto_left_c(message, random_code):

and everything should work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question