The write operation timed out telebot

Написал скрипт, который передаёт файл юзеру через тг бота (библиотека telebot). Сам файл весит 7 мб, за рамки телеграм бот апи не выходит. Но при попытке запустить скрипт выдаёт вот это:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "C:\Python39\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python39\lib\site-packages\urllib3\connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Python39\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1049, in _send_output
    self.send(chunk)
  File "C:\Python39\lib\http\client.py", line 971, in send
    self.sock.sendall(data)
  File "C:\Python39\lib\ssl.py", line 1204, in sendall
    v = self.send(byte_view[count:])
  File "C:\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:\Python39\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Python39\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:\Python39\lib\site-packages\urllib3\util\retry.py", line 531, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Python39\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "C:\Python39\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "C:\Python39\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python39\lib\site-packages\urllib3\connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Python39\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Python39\lib\http\client.py", line 1049, in _send_output
    self.send(chunk)
  File "C:\Python39\lib\http\client.py", line 971, in send
    self.sock.sendall(data)
  File "C:\Python39\lib\ssl.py", line 1204, in sendall
    v = self.send(byte_view[count:])
  File "C:\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\qwerty\Desktop\govno.pyw", line 243, in <module>
    tb.send_document(userid, f)
  File "C:\Python39\lib\site-packages\telebot\__init__.py", line 834, in send_document
    apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup,
  File "C:\Python39\lib\site-packages\telebot\apihelper.py", line 685, in send_data
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Python39\lib\site-packages\telebot\apihelper.py", line 107, in _make_request
    result = _get_req_session().request(
  File "C:\Python39\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python39\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python39\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'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\qwerty\Desktop\govno.pyw", line 246, in <module>
    tb.send_document(userid, f)
  File "C:\Python39\lib\site-packages\telebot\__init__.py", line 834, in send_document
    apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup,
  File "C:\Python39\lib\site-packages\telebot\apihelper.py", line 685, in send_data
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Python39\lib\site-packages\telebot\apihelper.py", line 113, in _make_request
    json_result = _check_result(method_name, result)
  File "C:\Python39\lib\site-packages\telebot\apihelper.py", line 140, 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

Код:

f = open(fzipname, "rb")
try:
    tb.send_document(userid, f)
except:
    time.sleep(5)
    tb.send_document(userid, f)
f.close()

Ответы (1 шт):

Автор решения: Alex Progd

Нашёл ответ, отписав на страницу гитхаба модуля. Добавил timeout в send_document и всё заработало.

tb.send_document(userid, f, timeout=10)
→ Ссылка