'can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first (DELETEWEBHOOK DOESN'T WORK)

I've done a bot for telegram and it worked but some days ago it appears a problem.

"can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first"

I use the deleteWebhook but it doesn't work (with the python-telegram-bot). I use the Python 3.6.12 version

data = {"url": ""}
    bot = telegram.Bot('XXXXXX ')

    if (normalize(update.message.text).upper() == 'HOLA'):
        chat_id = update.message.chat_id
        bot.sendMessage(chat_id, 'HOLA')
      
        
        #pload = {'chat_id':chat_id,'message_id':'123'}
        #r = requests.get('https://api.telegram.org/botXXXXXX/deleteWebhook')
        #r = requests.post('https://api.telegram.org/botXXXXXX/deleteWebhook',data = pload)
        r = requests.post('https://api.telegram.org/botXXXXXX/setWebhook',data = data)
        respuesta = bot.deleteWebhook()
        bot.sendMessage(chat_id, respuesta)
        respuesta = bot.deleteWebhook()

Could you tell me if there is a problem with that? How I can fix it?

Thank you



Solution 1:[1]

First off, I would highly recommend that if you are new to python telegram bot that you follow their bot tutorial. Using the bare metal API as you are doing is hard and prone to errors, just follow this step by step until you're more comfortable getting a basic bot up and running:

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot

As for the problem, your code at "r = requests...." is setting up a webhook. This isn't something you just toggle on and off, it's a completely different way of receiving and sending information to the Telegram servers and requires a lot of setup. I can't really recommend a fix as your code is mixing a lot of stuff up.

Solution 2:[2]

It usually happens when your bot token is occupied with online service or site. If you register your boy in any site, delete it.

I know it's late to answer but I write for other people.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tarson Crue
Solution 2 akbar