AutisticShark/Chevereto-Telegram-Bot

Not able to upload to Chevereto instance (SSL error)

Closed this issue · 5 comments

Hello.
I'm using Ubuntu 22.04 and Python 3.10, while using the bot, it shows the error:

2022-09-22 16:03:32,632 - apscheduler.scheduler - INFO - Scheduler started
image/jpeg
[('source', ('17fb854f-592b-4c80-9ef6-b4bc83fd603f.jpg', <_io.BufferedReader name='17fb854f-592b-4c80-9ef6-b4bc83fd603f.jpg'>, 'image/jpeg'))]
2022-09-22 16:03:36,216 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1076, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.10/http/client.py", line 998, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.10/ssl.py", line 1236, in sendall
    v = self.send(byte_view[count:])
  File "/usr/lib/python3.10/ssl.py", line 1205, in send
    return self._sslobj.write(data)
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2396)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='EXAMPLE.COM', port=443): Max retries exceeded with url: /api/1/upload/?key=APIKEYHERE&format=json (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/telegram/ext/dispatcher.py", line 557, in process_update
    handler.handle_update(update, self, check, context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/telegram/ext/handler.py", line 199, in handle_update
    return self.callback(update, context)
  File "/home/ubuntu/cheverto-bot/bot.py", line 35, in command_function
    function(update, context, *args, **kwargs)
  File "/home/ubuntu/cheverto-bot/bot.py", line 96, in image
    return_data = image_upload(request_format(image_name))
  File "/home/ubuntu/cheverto-bot/bot.py", line 134, in image_upload
    upload_response = requests.post(request_url, files = images)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/requests/adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='EXAMPLE.COM', port=443): Max retries exceeded with url: /api/1/upload/?key=APIKEYHERE&format=json (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))

And the telegram bot will stuck on message Downloading image from Telegram...

HTTPSConnectionPool(host='EXAMPLE.COM', port=443)

Are you sure this host is correct?

HTTPSConnectionPool(host='EXAMPLE.COM', port=443)

Are you sure this host is correct?

Yes, host and API keys are correct with my own instance's information, and command like help and storage status are working with no issue.

/storage_status

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           2.4G  2.0M  2.4G   1% /run
/dev/sda1        97G   19G   79G  20% /
tmpfs            12G  4.0K   12G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda15       98M  5.1M   93M   6% /boot/efi
tmpfs           2.4G  4.0K  2.4G   1% /run/user/1001

HTTPSConnectionPool(host='EXAMPLE.COM', port=443)

letsencrypt? use fullchain.pem (not cert.pem) in domain settings

command like help and storage status are working with no issue

Btw just to point out, if you can use other built-in bot commands other than upload means the bot is probably working as intended, Chevereto has docs for it's API v1 which you can debug using curl.

I had the same error, helped changing cert.pem to fullchain.pem in the nginx config on the host chevereto