-1

Please, help me to solve my problem. What's wrong with my code?

@dp.inline_handler()
async def inline_handler(query : types.InlineQuery):
    text = query.query or "echo"
    links = searcher(text)

    articles = [types.InlineQueryResultArticle(
        id = hashlib.md5(f'{link["id"]}'.encode()),hexdigest(),
        title = f'{link["title"]}',
        url = f'https://www.youtube.com/watch?v={link["id"]}',
        thumb_url = f'{link["thumbnails"][0]}',
        input_message_content=types.InputTextMessageContent(
            message_text=f'https://www.youtube.com/watch?v={link["id"]}')
    ) for link in links]

    await query.answer(articles, cache_time=60, is_personal=True)

Terminal shows this: ) for links in link] ^ SyntaxError: positional argument follows keyword argument

1 Answers1

0

The issue here is that id = hashlib.md5(f'{link["id"]}'.encode()),hexdigest(), is getting interpreted as two separate args. The first one is the keyword id but the second has no keyword assigned to it, and thus is positional. But in Python, at least, all positional arguments must go before keyword arguments, thus the issue. I'm unsure of what keyword argument hexdigest() is meant to be assigned to, but I hope this helps.

  • In [How to Answer](https://stackoverflow.com/help/how-to-answer), note the section _Answer Well-Asked Questions_, and the bullet point therein regarding questions "that have been asked and answered many times before". – Charles Duffy Jul 16 '22 at 18:05