python - 关于使用 O360 库访问文件:客户端错误:403 客户端错误:url 被禁止
问题描述
我正在尝试访问我的一个驱动器中的文件,这里是 python。所以我的代码如下:
account = Account(credentials=credentials)
storage = account.storage() # here we get the storage instance that handles all the storage options.
# list all the drives:
drives = storage.get_drives()
# get the default drive
my_drive = storage.get_default_drive() # or get_drive('drive-id')
# get some folders:
root_folder = my_drive.get_root_folder()
attachments_folder = my_drive.get_special_folder('attachments')
# iterate over the first 25 items on the root folder
for item in root_folder.get_items(limit=25):
if item.is_folder:
print(list(item.get_items(2))) # print the first to element on this folder.
elif item.is_file:
if item.is_photo:
print(item.camera_model) # print some metadata of this photo
elif item.is_image:
print(item.dimensions) # print the image dimensions
else:
# regular file:
print(item.mime_type) # print the mime type
它抛出此错误:客户端错误:403 客户端错误:禁止 url:https ://graph.microsoft.com/v1.0/me/drive/special/attachments | 错误消息:访问被拒绝
我在这里需要帮助,正如您在随附的屏幕截图中看到的那样,我也定义了正确的范围。也检查了类似的文章,但没有发现任何运气。
资源:https ://pypi.org/project/O365/#onedrive
谢谢。
解决方案
将范围修改为: scopes=['basic', 'message_all', 'openid', 'email', 'profile', 'offline_access', 'onedrive', 'onedriveall']
推荐阅读
- java - 无法访问 Android 更改系统设置权限
- multidimensional-array - 如何读取一个目录中的所有 NetCDF 文件并创建一个具有相同变量属性的单个 NetCDF 文件?
- python - 如何获取交易从未超过每月限额的行?
- c# - 您可以在 Dictionary 中的 ValueTuple 值中声明项目名称吗?
- flutter - Flutter 自定义条形图
- angular - MSAL 库的 Angular 9 问题
- python - 如果只安装了 Python 3.4,是否可以创建没有管理员权限的 Python 3.8 虚拟环境?中央操作系统
- vue.js - 如何在 Vue.js 中使用 require.context 设置延迟加载的路由
- mysql - 为什么用户的加入日期会发生变化
- python - pandas汇总统计的均值测试差异?