Задать вопрос
@downhill_1s
Малыш программист

Хочу сделать чтобы при отправке команды боту он отправлял все видео из папки. Что сделать чтобы не было ошибки?

import telebot
import config
import os

bot = telebot.TeleBot(config.TOKEN)

fol_vid = os.path.join(r"C:\Users\User\PycharmProjects\Security_ai")

@bot.message_handler(commands=['video'])
def send_video(message):
    for file in os.listdir(fol_vid):
        if file.endswith(".mp4"):
            video_path = os.path.join(fol_vid, file)
            bot.send_video(message.chat.id, open(video_path, 'rb'))

bot.infinity_polling()


Выдает такую ошибку :
2021-11-10 19:24:58,520 (__init__.py:617 MainThread) ERROR - TeleBot: "Infinity polling exception: ('Connection aborted.', timeout('The write operation timed out'))"
2021-11-10 19:24:58,520 (__init__.py:619 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1049, in _send_output
    self.send(chunk)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 971, in send
    self.sock.sendall(data)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1204, in sendall
    v = self.send(byte_view[count:])
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1173, in send
    return self._sslobj.write(data)
socket.timeout: The write operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\util\retry.py", line 532, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\urllib3\connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1049, in _send_output
    self.send(chunk)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 971, in send
    self.sock.sendall(data)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1204, in sendall
    v = self.send(byte_view[count:])
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1173, in send
    return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', timeout('The write operation timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\__init__.py", line 613, in infinity_polling
    self.polling(none_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout,
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\__init__.py", line 660, in polling
    self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\__init__.py", line 722, in __threaded_polling
    raise e
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\__init__.py", line 682, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\util.py", line 135, in raise_exceptions
    raise self.exception_info
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\util.py", line 87, in run
    task(*args, **kwargs)
  File "C:\Users\User\PycharmProjects\Security_ai\commands_tests.py", line 20, in send_video
    bot.send_video(message.chat.id, open(video_path, 'rb'))
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\__init__.py", line 1259, in send_video
    apihelper.send_video(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\apihelper.py", line 676, in send_video
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\telebot\apihelper.py", line 151, in _make_request
    result = _get_req_session().request(
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\User\PycharmProjects\Security_ai\venv\lib\site-packages\requests\adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', timeout('The write operation timed out'))
"
2021-11-10 19:25:07,525 (__init__.py:623 MainThread) ERROR - TeleBot: "Infinity polling: polling exited"
2021-11-10 19:25:07,525 (__init__.py:625 MainThread) ERROR - TeleBot: "Break infinity polling"
  • Вопрос задан
  • 3233 просмотра
Подписаться 1 Простой 6 комментариев
Пригласить эксперта
Ответы на вопрос 1
Levman5
@Levman5
print(“Hello World!”)
Замени bot.infinity_polling() на bot.polling() и попробуй поставить задержку между отправками сообщений
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы