телеграмм бот

valestina123

Новичок
Пользователь
Авг 7, 2023
1
0
1
Здравствуйте! не могу понять почему выдает ошибку:
2023-08-07 20:45:52,333 (__init__.py:1083 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified"
2023-08-07 20:45:52,335 (__init__.py:1085 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\__init__.py", line 1074, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\util.py", line 147, in raise_exceptions
raise self.exception_info
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\util.py", line 90, in run
task(*args, **kwargs)
File "C:\Users\vtbal\PycharmProjects\TelegaBot\main.py", line 40, in on_clik2
bot.send_photo(message.chat.id, random.choice(files))
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\__init__.py", line 1825, in send_photo
apihelper.send_photo(
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\apihelper.py", line 494, in send_photo
return _make_request(token, method_url, params=payload, files=files, method='post')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\apihelper.py", line 162, in _make_request
json_result = _check_result(method_name, result)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vtbal\PycharmProjects\TelegaBot\venv\Lib\site-packages\telebot\apihelper.py", line 189, in _check_result
raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified
"
вот, выдает из за кода:
def on_clik2(message):
files = ['mem1.jpg', 'mem2.jpg', 'mem3.jpg']
try:
handles = [open(file, 'rb') for file in files]
pass
except IOError as e:
print('Operation failed: %s' % e.strerror)
finally:
for handle in handles:
handle.close()
if message.text == 'Мем дня':
bot.send_photo(message.chat.id, random.choice(files))
заранее огромное спасибо!)
 

4olshoy_blen

Популярный
Пользователь
Ноя 13, 2022
419
113
43
Python:
from telebot.types import InputFile

@bot.message_handler(func=lambda message: message.text == 'Мем дня')
def on_clik2(message):
    files = ['mem1.jpg', 'mem2.jpg', 'mem3.jpg']
    bot.send_photo(message.chat.id, InputFile(random.choice(files)))
 

Форум IT Специалистов