You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Microsoft Graph Python SDK上传文件时遭遇501 (notSupported)错误的求助

Microsoft Graph Python SDK上传文件时遭遇501 (notSupported)错误的求助

我想照着官方文档里的HTTP上传文件示例,用Microsoft Graph Python SDK实现文件上传功能,写了下面这段代码:

async with aiofiles.open(src_file_path, 'rb') as file:
    file_content = await file.read()

dest_folder_name = "FolderA"
src_file_name = "FileB.txt"
dest_file_path = f"{dest_folder_name}/{src_file_name}"
drive_item_id = f"/root:/{dest_file_path}:"
uploaded_file = await self.client.drives.by_drive_id(drive_id).items.by_drive_item_id(drive_item_id).content.put(file_content)

结果运行后直接抛出了501错误,具体的错误信息如下:

msgraph.generated.models.o_data_errors.o_data_error.ODataError: 
         APIError
         Code: 501
         message: None
         error: MainError(additional_data={}, code='notSupported', details=None, inner_error=InnerError(...,
message='Cannot upload content to an item representing a folder.',
target=None)

我实在搞不明白问题出在哪——明明我指定的路径是FolderA/FileB.txt,是一个文件路径啊,为什么会被识别成文件夹呢?有没有用过这个SDK的朋友能帮我分析下原因,给个解决办法呀?

备注:内容来源于stack exchange,提问作者Luca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 14:28:03