How to resolve TypeError: __init__() missing 1 required positional argument: 'update_queue'?
Asked Answered
M

2

6

I want to create a Telegram bot that checks for a new post on a website (currently every 15s for testing purposes). If so, it should send a message with content from the post into the Telegram channel.

For this I already have the following "code skeleton": (The fine work in terms of formatting and additions comes later)

import requests
import asyncio
from bs4 import BeautifulSoup
from telegram import InputMediaPhoto
from telegram.ext import Updater

# Telegram Bot API Token
API_TOKEN = 'XXXXXXXXXXXXXXXXX'

# URL of the website
URL = 'https://chemiehalle.de'

# List for storing seen posts
seen_posts = []

# Function for fetching posts
def get_posts():
    # Send request to the website
    res = requests.get(URL)
    # Parse HTML content
    soup = BeautifulSoup(res.content, 'html.parser')
    # Find all posts on the website
    posts = soup.find_all('article')
    # Iterate over each post
    for post in posts:
        # Get title of the post
        title = post.find('h2', class_='entry-title').text
        # Check if post has already been seen
        if title not in seen_posts:
            # Get image URL
            image_src = post.find('img')['src']
            # Get short text of the post
            text = post.find('div', class_='entry-content clearfix').find('p').text
            # Send image, title, and text as message
            bot.bot.send_media_group(chat_id='@chemiehalleBot', media=[InputMediaPhoto(media=image_src, caption=title + '\n\n' + text)])
            # Add title of the post to the list of seen posts
            seen_posts.append(title)

# Main loop
async def main():
    while True:
        # Call get_posts function every 15s
        get_posts()
        print("Check for new posts")
        await asyncio.sleep(15)

# Initialize Telegram Bot
updater = Updater(API_TOKEN)
bot = updater.bot

# Start main loop
asyncio.run(main())

So far I have found out that updater = Updater(API_TOKEN, use_context=True) produces errors and so I have removed use_context=True following the instructions from other posts on this site.

Since that I am encountering the error TypeError: __init__() missing 1 required positional argument: 'update_queue' in the updater = Updater(API_TOKEN) line.

But unfortunately I don't know what to change. According to this, the constructor of Updater needs an additional argument update_queue. But I have no idea which one this should be and where I should get it from.

Can you help me please?

Thank you very much for the support!

Meow answered 6/2, 2023 at 15:3 Comment(2)
telegram.ext.Updater has two parameters - bot and update_queue you need to supply values for both params.Takishatakken
Does this answer your question? Unable to run Python Telegram Bot Package - ErrorTalich
M
3

You probably have the wrong telegram version.

I am a bit old fashion, but for me version 13 still works great.

So simply replace your library version by running:

pip install python-telegram-bot==13.13
Madson answered 24/3, 2023 at 19:51 Comment(2)
That's what did the trick. I downgraded from v20 to 13.13 and now everything works fine. Thank you!Meow
Why downgrade instead of fixing your code to use the current version correctly?Tetradymite
A
0

The accepted answer is good, but I want to add an improvement to it since there have been changes to the API, even for the v13, in v13.15 for example you can access "message_thread_id"

So simply replace your library version by running:

pip install python-telegram-bot==13.15
Apotropaic answered 16/7 at 5:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.