python - 尝试上传图片时出现 [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))
解决方案
必须确保您的 Python IDE 已以管理权限启动,或者确保该文件夹具有较少的权限以让 Python 做任何他想做的事情,将一些文件或图片下载到受保护的文件夹中,这样您就永远不会再拥有权限错误。
您收到权限错误,因为您尝试将文件写入/复制/粘贴或下载到受保护的 C: 路径中。
默认情况下,C: 路径中的任何内容都受到保护,即使您使用 Python 创建自己的文件夹也是如此。
希望我对您的问题有所帮助!
推荐阅读
- javascript - 将 javascript 模块与原生 SDK 集成
- windows - 如何在 Windows 的单个节点中安装 Kafka MultiBroker 系统
- vim - 如何在 vim 中保存所有缓冲区(即使它们没有更改)?
- wordpress - Wordpress 如何为 API REST 设置子目录
- java - 可以在 ImageView 中放置 TextView 吗?
- c# - 如何在 mvc 中禁用某些列或属性验证?
- java - 如何在我的世界 GuiMainMenu 中制作不可调整大小的菜单?
- firebase - 特定 Firebase 规则
- javascript - 使用 Node JS 对 Google API 进行身份验证
- ffmpeg - 将 MOV 转换为 WEBP