首页 > 解决方案 > 尝试上传图片时出现 [Errno 13] Permission denied 错误

问题描述

await message.attachments[0].save('Images/' + '{0}'.format(message.attachments[0].filename))
            print('Downloaded {0}'.format(message.attachments[0].filename))
            path = 'C:/xxxx/xxxx/xxxx/xxxx/Images/'
            os.chdir(path)
            files = sorted(os.listdir(os.getcwd()), key=os.path.getctime)
            images = (files)
            media_ids = [api.media_upload(i).media_id_string  for i in images]
            api.update_with_media(path, status='{0}'.format(message.content), media_ids=media_ids)
            print('{0.author.name} posted an (Image Attachment)'.format(message))

出于某种原因,由于这个问题,我似乎无法在 Twitter 上上传多张图片。

修复了这个问题,因为我忘记包含files但现在它只上传一张图片而不是全部:

await message.attachments[0].save('Images/' + '{0}'.format(message.attachments[0].filename))
            print('Downloaded {0}'.format(message.attachments[0].filename))
            path = 'C:/xxxx/xxxx/xxxx/xxxx/Images/'
            os.chdir(path)
            files = sorted(os.listdir(os.getcwd()), key=os.path.getctime)
            images = (files)
            media_ids = [api.media_upload(i).media_id_string  for i in images]
            api.update_with_media(path + files[0], status='{0}'.format(message.content), media_ids=media_ids)
            print('{0.author.name} posted an (Image Attachment)'.format(message))

标签: pythonpython-3.xtweepydiscord.py

解决方案


必须确保您的 Python IDE 已以管理权限启动,或者确保该文件夹具有较少的权限以让 Python 做任何他想做的事情,将一些文件或图片下载到受保护的文件夹中,这样您就永远不会再拥有权限错误。

您收到权限错误,因为您尝试将文件写入/复制/粘贴或下载到受保护的 C: 路径中。

默认情况下,C: 路径中的任何内容都受到保护,即使您使用 Python 创建自己的文件夹也是如此。

希望我对您的问题有所帮助!


推荐阅读