Столкнулся с проблемой , при попытке отправить пользователю фотографию - все успешно. Но как только я нажимаю кнопку /start для повторной отправки фото - ошибка. Приходится перезапускать код. Помогите пофиксить. Не задержка ничего не помогает..
код
import telebot
from telebot import types
bot = telebot.TeleBot('-')
file = open('pon.jpg' , 'rb')
@bot.message_handler(commands=['start'])
def first(message):
bot.send_photo(message.chat.id , file)
bot.polling()
erorrs
2022-12-25 23:40:14,352 (__init__.py:1083 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: file must be non-empty"
2022-12-25 23:40:14,353 (__init__.py:1085 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\__init__.py", line 1074, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\util.py", line 156, in raise_exceptions
raise self.exception_info
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\util.py", line 100, in run
task(*args, **kwargs)
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\__init__.py", line 6308, in _run_middlewares_and_handler
result = handler['function'](message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fokin\PycharmProjects\pythonProject1\venv\python_project\test_coding.py", line 54, in first
bot.send_photo(message.chat.id , file)
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\__init__.py", line 1821, in send_photo
apihelper.send_photo(
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\apihelper.py", line 492, in send_photo
return _make_request(token, method_url, params=payload, files=files, method='post')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\Lib\site-packages\telebot\apihelper.py", line 162, in _make_request
json_result = _check_result(method_name, result)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fokin\AppData\Local\Programs\Python\Python311\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: file must be non-empty
"
Process finished with exit code 0