Hey guys, I’m having trouble with my Telegram bot on PythonAnywhere. It was fine on the free account, but now I’m using a paid one and it’s acting up. I keep getting this error in the logs:
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]
I’m using Python 3.7, pyTelegramBotAPI, and Flask. Here’s a simplified version of my code:
I encountered a similar problem when deploying my Telegram bot on PythonAnywhere. The SSL error you’re seeing often stems from outdated libraries or configuration issues. Here’s what worked for me:
First, ensure you’re using the latest version of pyTelegramBotAPI. You can upgrade it with:
pip install --upgrade pyTelegramBotAPI
Also, double-check your webhook URL. Make sure it’s using HTTPS and matches exactly what you’ve set in your Telegram bot settings.
If the issue persists, try explicitly specifying the SSL context in your Flask app:
I’ve been down this road before with PythonAnywhere and Telegram bots. The SSL error you’re seeing is a real pain. One thing that sorted it for me was adjusting the SSL version in my code. Try adding this near the top of your script:
import ssl
from functools import partial
ssl.wrap_socket = partial(ssl.wrap_socket, ssl_version=ssl.PROTOCOL_TLSv1_2)
This forces the use of TLS 1.2, which PythonAnywhere seems to prefer. Also, make sure your bot token is correct and that you’ve whitelisted the Telegram API IP addresses in your PythonAnywhere settings. If you’re still stuck, their support team is pretty helpful - might be worth reaching out to them directly.