首页 > 解决方案 > 关于使用 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

谢谢。

标签: pythonazuremicrosoft-graph-api

解决方案


将范围修改为: scopes=['basic', 'message_all', 'openid', 'email', 'profile', 'offline_access', 'onedrive', 'onedriveall']


推荐阅读