dimanche 21 avril 2019

Whenever i choose a random file from a folder it says file not found

I'm trying to make the code to choose a random file from a folder and tweet it on tweeter, but i get an error

I'm on windows 10, haven't tried anything else.


path ='C:/Users/Name/Desktop/twitbot/home/gay'
files = os.listdir(path)
index = random.randrange(0, len(files))

message = "Picture of the moment!"
with open(files[index], 'rb') as photo:
    twitter.update_status_with_media(status=message, media=photo)

I expect the code to choose a picture and to post it on Twitter, but it says 'FileNotFoundError: [Errno 2] No such file or directory: '753.jpg''




Aucun commentaire:

Enregistrer un commentaire