R
R
Ruslan2018-05-20 22:00:55
Python
Ruslan, 2018-05-20 22:00:55

Why telegram bot on python2.7 works on 3.4 no?

Wrote an elementary bot in python, the code works if run on 2.7 with warnings about SSL, the code does not work on py3, it starts, but does not accept commands. Maybe it has something to do with blocking? How can you run?

from telegram.ext import Updater, CommandHandler

def start_bot(bot, update):
    mytext = """Hello world /start
    """ 
    update.message.reply_text(mytext)
    print("start")

def main():
    updtr = Updater('MY_TOKEN')

    updtr.dispatcher.add_handler(CommandHandler("start", start_bot))
    updtr.start_polling()
    updtr.idle()

if __name__ == "__main__":
    main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Simon Osipov, 2018-05-21
@SimonOsipov

It's hard to say so, try logging (insert code before def main:

import logging

logging.basicConfig(
  handlers=[
    logging.FileHandler(
      'bot.log',
      'w',
      'utf-8'
    )
  ],
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  level=logging.DEBUG,
)

Start the bot, send the /start command, shut down the bot and look in bot.log
You should be interested in calling the API:
It may very well be that the bot cannot access the API, precisely because of the locks. This will show up in the log.
Faster option: turn on the VPN and try again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question