Q
Q
qwwwwwty2021-10-26 15:21:20
Python
qwwwwwty, 2021-10-26 15:21:20

What is the error, Python Aiogram?

I don't understand what the error is and I don't understand how to fix this error. the code:

async def hellopicture(dp: Dispatcher):
    files = random.choice(list(os.walk('C:/Users/andis/Desktop/Python/EasyBot/Picture'))[0][-1])
    img = open(files, 'rb')
    print(img)
    img.close()
    photo = types.InputFile(path_or_bytesio=files)
    await dp.bot.send_photo(config.GROUP_ID, photo=photo)
    

def scedule_jobs2():
    scheduler.add_job(hellopicture, "interval", seconds = 10, args=(dp, ))

scedule_jobs2()


an error in the attached file:
by the way, in fact, the bot should send a random picture from the folder, but it does not do this and does not send it at all.6177f26ac67da443320159.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananchenko, 2021-10-26
@qwwwwwty

Everything is written in English here, and everything is clear
. The translation of the error is something like this:
I can’t find the file or directory '4.jpg'
The problem is that you only looked at the path to these pictures, but when you try to take this file, the bot is in your directory (That is, where you launched the .py script)

files = random.choice(list(os.walk('C:/Users/andis/Desktop/Python/EasyBot/Picture'))[0][-1])
img = open(f'C:/Users/andis/Desktop/Python/EasyBot/Picture/{files}', 'rb')

This should fix the problem, you can also change directories globally via the os module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question