Can't download files, PermissionError: [Errno 13] Permission denied: 'C:\\Users\\***\\Desktop' with telepot

Can't download files, PermissionError: [Errno 13] Permission denied: 'C:\\Users\\***\\Desktop' with telepot

我正在尝试使用 telepot 使用电报机器人下载一些文件,但是当我尝试下载它时,它给了我这个错误:

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

这是当前代码:

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())

您正在尝试保存名为 C:\Users\***\Desktop 的文件。你不能那样做,因为 C:\Users\***\Desktop 是一个目录。

在 Windows 上,您将在尝试打开目录进行读取或写入时遇到 permission-denied 错误,就好像它是文件一样。

您必须以某种方式指定文件名。它可能在您收到的 msg 对象中,我不知道。

而不是写作

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

尝试

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