0

I am trying to run telegram bot using python 3.9 . Getting SSL wrong_version_number exception. I updated the certificate required as NONE in file /Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/utils/request.py as below , still getting the same error:

kwargs = dict(
    maxsize=con_pool_size,
    cert_reqs='CERT_NONE',
    ca_certs=certifi.where(),
    socket_options=sockopts,
    timeout=urllib3.Timeout(connect=self._connect_timeout, read=read_timeout, total=None),
)

My main.py

import logging
from telegram.ext import *
import responses

API_KEY = 'my-api-key'

# Set up the logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logging.info('Starting Bot...')


def start_command(update, context):
    update.message.reply_text('Hello there! I\'m a bot. What\'s up?')


def help_command(update, context):
    update.message.reply_text('Try typing anything and I will do my best to respond!')


def custom_command(update, context):
    update.message.reply_text('This is a custom command, you can add whatever text you want here.')


def handle_message(update, context):
    text = str(update.message.text).lower()
    logging.info(f'User ({update.message.chat.id}) says: {text}')

    # Bot response
    response = responses.get_response(text)
    update.message.reply_text(response)


def error(update, context):
    # Logs errors
    logging.error(f'Update {update} caused error {context.error}')


# Run the programme
if __name__ == '__main__':
    updater = Updater(API_KEY, use_context=True)
    dp = updater.dispatcher

    # Commands
    dp.add_handler(CommandHandler('start', start_command))
    dp.add_handler(CommandHandler('help', help_command))
    dp.add_handler(CommandHandler('custom', custom_command))

    # Messages
    dp.add_handler(MessageHandler(Filters.text, handle_message))

    # Log all errors
    dp.add_error_handler(error)

    # Run the bot
    updater.start_polling(1.0)
    updater.idle()

Complete error stack-trace :

Traceback (most recent call last):
  File "/Users/abc/Documents/professional/projects/telegram-bot/main.py", line 55, in <module>
    updater.start_polling(1.0)
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/ext/updater.py", line 422, in start_polling
    self._init_thread(self.dispatcher.start, "dispatcher", ready=dispatcher_ready)
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/ext/updater.py", line 342, in _init_thread
    name=f"Bot:{self.bot.id}:{name}",
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/bot.py", line 372, in id
    return self.bot.id
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/bot.py", line 366, in bot
    self._bot = self.get_me()
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/bot.py", line 133, in decorator
    result = func(*args, **kwargs)
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/bot.py", line 453, in get_me
    result = self._post('getMe', timeout=timeout, api_kwargs=api_kwargs)
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/bot.py", line 298, in _post
    return self.request.post(
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/utils/request.py", line 361, in post
    result = self._request_wrapper(
  File "/Users/abc/Library/Python/3.9/lib/python/site-packages/telegram/utils/request.py", line 265, in _request_wrapper
    raise NetworkError(f'urllib3 HTTPError {error}') from error
telegram.error.NetworkError: urllib3 HTTPError [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)
beskar
  • 55
  • 1
  • 10
  • Please check for wrong proxy settings - see [this answer](https://stackoverflow.com/a/50842202/3081018) which might point out the problem. – Steffen Ullrich Oct 16 '22 at 09:55
  • @SteffenUllrich Where can I configure http_proxy on mac ? I tried setting it in network->advance->proxies . But no luck. – beskar Oct 16 '22 at 10:16
  • This is typically done in the environment variables http_proxy and https_proxy (maybe also uppercase). Apart from that - have you checked that access to the site you are trying to access is possible at all from the machine you are using, i.e. not blocked, no captive portal in between or similar? – Steffen Ullrich Oct 16 '22 at 10:41

0 Answers0