'Bot keeps showing the same error when kicked TELEPOT

I've created a telegram bot that only prints the message that I send, everything works correctly until I block it or add/kick it from a group, when I do this the bot keeps showing this error: 1

Here's the code:

import telepot
from telepot.loop import MessageLoop
from pprint import pprint
import time

TOKEN="..."

def handler(msg):
    content, chat, id=telepot.glance(msg)
    pprint(msg)

bot=telepot.Bot(TOKEN)
bot.message_loop(handler)

while True:
    time.sleep(10)

I've also tried using the getUpdates function and it keeps printing all the messages, even the old deleted ones. I think that the problem is caused by "stored" messages but I don't know how to fix it.

I'm using:

  • telepot version 12.7
  • python 3.9.0


Solution 1:[1]

I hope that you fixed this problem already.. But to help you or any future visitors I am sharing a simple solution.

pip uninstall telepot

pip install telepota

As telepot is not being maintained or updated since 2018 telegrams Bot API update raised the issue which is fixed in telepota. Telepota is a fork of Telepot which is Being updated timely.. Best part is you don't need a single change in your code..

Solution 2:[2]

Example

The example works by having a data object, which stores the captions and image URLs. Then, there is a clone template. It loops through each and clones the template, and replaces each element with the correct content. Then it adds it to the HTML with .appendChild.

Solution 3:[3]

You can write a function doing this job. Creating copies of your element and change the attributes corresponding to your new data.

function copyAndChangeImageAndCaption(){

    const images = [
    {imageUrl: "images/de.jpg", caption: "De"},
    {imageUrl: "images/it.jpg", caption: "It"},
    {imageUrl: "images/fr.jpg", caption: "Fr"}
];

    images.forEach(image => {
        const el = document.getElementsByClassName('col-lg-4 mb-5 col-md-6');
        let copy = el[0].cloneNode(true)
        copy.getElementsByClassName('thumbnail')[0].childNodes[0].src=image.imageUrl;
        copy.getElementsByClassName('heading')[0].childNodes[0].innerHTML = image.caption;
        document.getElementsByClassName('container')[0].appendChild(copy);
    });
}
<div class='container'>
    <div class="col-lg-4 mb-5 col-md-6">
        <div class="wine_v_1 text-center pb-4">
             <a class="thumbnail d-block mb-4"><img src="images/im.jpg" alt="Image" class="img-fluid"></a>
            <div>
                <h3 class="heading mb-1"><a href="#">Us</a></h3>
            </div>
        </div>
   </div>
</div>

<button onClick="copyAndChangeImageAndCaption()">Add images</button>

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 Etienne Kaiser
Solution 2 sean-7777
Solution 3