A
A
Andrey Zuev2020-06-01 16:53:28
Python
Andrey Zuev, 2020-06-01 16:53:28

How to run pyTelegramBotAPI?

I decided to try writing my own telegram bot:

import telebot

bot = telebot.TeleBot('МойТокен')

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, ты написал мне /start')


bot.polling(none_stop=True)


Run - error:
Mistake
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /botМойТокен/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x040C7838>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))


Okay, downloaded Windscribe, turned on the VPN, but the error remains:
Mistake 2
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=3.5)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2020-06-01
@CoolGaming

try instead on Also check Windscribe's connection, suddenly connected to CIS countries. In the worst case, reinstall the library and regenerate the token for the bot. Also try writing this:bot.polling(none_stop=True)bot.infinity_polling(True)

if __name__ == '__main__':
    while True:
        try:
            bot.polling(none_stop=True)
        except Exception as e:
            time.sleep(3)
            print(e)

A
Alexander, 2020-06-01
@swwso1

For some reason, the bot cannot connect to the telegram servers. It's strange that with the use of VPN the error remained. Perhaps the matter is in the Internet connections, or it is worth changing the VPN or its server. Check the connection on whoer.net, if it shows that your ip is not Russian, then it's not a VPN.

S
Sasha345534, 2020-06-01
@Sasha345534

Go to @BotFather and create a bot, after creation you will be given a Token. You paste it here
bot = telebot.TeleBot('MyToken')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question