M
M
misha_dyrachok2021-11-06 00:08:23
Python
misha_dyrachok, 2021-11-06 00:08:23

Task(*args, **kwargs) error in python telegram bot code, how to fix?

According to my idea, the bot had to respond to certain messages with an image.
When I sent a certain message 1 time, everything was fine, but when I sent a message 2 times, the following error appeared:

File "C:\Users\Zlaya_Belka\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 59, in run
    task(*args, **kwargs)
  File "E:\1\bot1.py", line 10, in get_text_messages
    bot.send_photo(message.chat.id,serdechko1)
  File "C:\Users\Zlaya_Belka\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 635, in send_photo
    apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup,
  File "C:\Users\Zlaya_Belka\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\apihelper.py", line 262, in send_photo
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Users\Zlaya_Belka\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\apihelper.py", line 56, in _make_request
    return _check_result(method_name, result)['result']
  File "C:\Users\Zlaya_Belka\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\apihelper.py", line 75, in _check_result
    raise ApiException(msg, method_name, result)

Here is the code itself:
import telebot
bot = telebot.TeleBot('ТОКЕН')
serdechko1 = open('1/photo/serdechki1.jpg', 'rb')


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

def get_text_messages(message):
  if message.text == "❤️":
 		    bot.send_photo(message.chat.id,serdechko1)
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "❣️":
    		bot.send_message(message.chat.id, "❣️")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")
  elif message.text == "":
    		bot.send_message(message.chat.id, "")

bot.polling(none_stop=True, interval=0)

Part of the code has been removed. it contains obscene language and the moderator deleted the question.
In place of empty quotes are hearts <3
In the part of the code with obscene language, everything seems to be normal.
The code is very rough because it was created for more fun communication with friends.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jan, 2021-11-11
@Buchachalo

with open('1/photo/serdechki1.jpg', 'rb') as outfile:
    bot.send_photo(message.chat.id, outfile)

Try this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question