mercredi 10 novembre 2021

why am i getting file not found ... (python)

So basically i am trying to create an bot that posts random images from my folders to an api, but when i try to do the request i got an error, following is the import part of the code

path= "frames/Dc1001/"

img = random.choice(os.listdir(path))
print (img)
upload_url = vk.photos.getWallUploadServer(owner_id=-id, from_group=1)['upload_url']
request = requests.post(upload_url, files={'file': open(img, "rb")})
save_wall_photo = vk.photos.saveWallPhoto(owner_id=-id, from_group=1, photo=request.json()['photo'],server = request.json()['server'], hash=request.json()['hash'])
saved_photo = "photo" + str(save_wall_photo[0]['owner_id'])+"_"+ str(save_wall_photo[0]['id'])

def post_topic(owner_id, from_group, message, attachments):
    session.method("wall.post", {
        "owner_id": -id,
        "from_group": 1,
        "message": message,
        "attachments": saved_photo
    })

while True:
    post_topic(-id, 1, "testttt", saved_photo)
    time.sleep(30)

i get the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'imgNumber.png'

note: it prints the right img number and yes i have all the libraries needed imported, and where i put -id its cause i need to hide it, thanks in advance for any help




Aucun commentaire:

Enregistrer un commentaire