telegram bot ssl.SSLWantWriteError: The operation did not complete

Viewed 19
Writing telegram bot and have following issue:
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Admin\Desktop\TGBot\functions.py", line 36, in serve_user
    print(f"Sent {filename}")
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\telebot\__init__.py", line 1776, in send_audio
    apihelper.send_audio(
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\telebot\apihelper.py", line 866, in send_audio
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\telebot\apihelper.py", line 155, in _make_request
    result = _get_req_session().request(
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Admin\Desktop\TGBot\venv\lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot5719168851:AAFsyBNALIggcpY7oX5PKx9bs1Ie9TF-yyU/sendAudio?chat_i
d=729118904 (Caused by SSLError(SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2483)')))

Bot downloads song and sends to telegram user. Error happens during sending phase, though song is downloaded and everything is OK with that. Probably it depends on song's size, but it is said that telebot can send filex up to 50MB, this thing happens with 7MB files. Now it is being catched and bot says that he can't find song, but how could i fix this issue?

print(f"{message.from_user.full_name} : {message.text} : {message.id}")
    if message.text.lower() == '/help':
        bot.send_message(message.chat.id, "Just send me title of song and you will get it")
    elif message.text[0] == '/':
        bot.send_message(message.chat.id, "I don't support that command")
    else:
        try:
            url = request_page(message.text)
            filename = f"{message.from_user.id}${message.id}.mp3"
            audiofile = requests.get(url)
            try:
                with open(f'{source}{filename}', 'wb') as f:
                    f.write(audiofile.content)
                    print(f"Downloaded {filename}")
            except OSError:
                print('Could not download song')
            print(f"Sending {filename}")
            bot.send_audio(message.chat.id, audio=open(f'{source}{filename}', 'rb'))
            print(f"Sent {filename}")
            if os.path.isfile(f'{source}{filename}'):
                os.remove(f'{source}{filename}')
                print(f"Deleted {filename}")
        except (TypeError, ssl.SSLError, requests.exceptions.ConnectionError):
            bot.send_message(message.chat.id, 'Could not find a song')
            print("Could not find a song")
0 Answers
Related