i'm trying to download some files with a telegram bot using telepot, but when I try to download it, it gives me this error:

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\***\\Desktop'

This is the current code:

def on_chat_message(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    file_id = msg['document']['file_id']
    bot.download_file(file_id,os.getcwd())
1

There are 1 best solutions below

0
On BEST ANSWER

You are attempting to save a file named C:\Users\***\Desktop. You can't do that because C:\Users\***\Desktop is a directory.

On Windows, you will get a permission-denied error attempting to open a directory for reading or writing as if it were a file.

You will have to specify the name of the file somehow. It may be in the msg object you receive, I don't know.

Instead of writing

    bot.download_file(file_id,os.getcwd())

try

    file_name = "somefilenamehere.txt" # or look up from msg
    bot.download_file(file_id, os.path.join(os.getcwd(), file_name))