Hey guys, I’m stuck with a problem. My Telegram bot was working fine on a free account, but now I’m having trouble on a paid one. I keep getting this error: “OpenSSL.SSL.Error: [(‘SSL routines’, ‘ssl3_get_record’, ‘decryption failed or bad record mac’)]”. It’s messing up my bot’s functionality.
I’m using python3.7, pyTelegramBotAPI, and flask. Here’s a simplified version of my code:
import telebot
import flask
bot_token = 'your_bot_token_here'
bot = telebot.TeleBot(bot_token, threaded=False)
app = flask.Flask(__name__)
@app.route('/webhook', methods=['POST'])
def handle_webhook():
if flask.request.headers.get('content-type') == 'application/json':
update = telebot.types.Update.de_json(flask.request.get_data().decode('utf-8'))
bot.process_new_updates([update])
return ''
else:
flask.abort(403)
@bot.message_handler(commands=['greet'])
def send_welcome(message):
bot.reply_to(message, "Welcome! How can I help you today?")
bot.remove_webhook()
bot.set_webhook(url='https://your-domain.com/webhook')
Any ideas on how to fix this SSL error? I’m really confused about why it’s happening on the paid account but not the free one. Thanks for any help!
I’ve encountered similar SSL issues when deploying bots on different hosting environments. One thing that often gets overlooked is the Python version compatibility. Since you’re using Python 3.7, make sure your hosting provider fully supports it and has all the necessary SSL libraries installed.
Another potential fix is to explicitly set the SSL context in your Flask app. Try adding this before running your app:
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain('path/to/your/certificate.pem', 'path/to/your/key.pem')
Then use this context when running your Flask app:
app.run(ssl_context=context)
This approach forces the use of TLS 1.2, which might resolve the SSL handshake issues you’re experiencing. Don’t forget to replace the certificate paths with your actual SSL certificate files provided by your hosting service.
I’ve dealt with similar SSL issues before. One thing to check is your hosting provider’s OpenSSL version. Some providers use older versions that can cause compatibility problems.
Another potential fix is to try setting a custom SSL context in your code. You can do this by adding:
import ssl
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
Then modify your bot.set_webhook line to:
bot.set_webhook(url=‘https://your-domain.com/webhook’, certificate=open(‘path/to/cert.pem’, ‘r’))
This bypasses some SSL checks which might be causing issues. Just remember, this is a temporary fix - for production, you’ll want proper SSL configuration.
Also, double-check your hosting provider’s documentation. They might have specific requirements for SSL setup with Python applications.
hey isaac, that ssl error sounds like a real pain. have u checked ur hosting provider’s ssl config? sometimes they mess with default settings. also, try updating ur pyTelegramBotAPI and OpenSSL libraries. those updates can fix weird issues. good luck man!