microsoftgraph / microsoftgraph/msgraph-sdk-python

Error 400 after successful file upload

未关闭
#1,067 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area:uploads type:bug
主要语言
Python
星标
630
派生
96
平均合并
15 小时 20 分钟
30 天内合并 PR
3

描述

Describe the bug

I'm testing an upload process, here's an anonymized snippet of the code:

    async def _upload_file(self, drive_id, filename, file_content, folder_name=None):
        properties = DriveItemUploadableProperties(
            additional_data={
                "@microsoft.graph.conflictBehavior" : "replace",
                },
            )
        request_body =  CreateUploadSessionPostRequestBody(item=properties)
        if folder_name is not None:
            filename = folder_name + '/' + filename
        session = await (
            self.client
            .drives.by_drive_id(drive_id)
            .items.by_drive_item_id(f"root:/{filename}:")
            .create_upload_session.post(body=request_body)
            )
        large_file_session = LargeFileUploadSession(
            upload_url=session.upload_url,
            expiration_date_time=session.expiration_date_time,
            additional_data=session.additional_data,
            is_cancelled=False,
            next_expected_ranges=session.next_expected_ranges
        )
        task = LargeFileUploadTask(upload_session=large_file_session, request_adapter=self.client.request_adapter, stream=file_content)

        upload_result = await task.upload()
        return upload_result

The upload proceeds as expected, but I get the following exception anyway:

APIError
Code: 400
message: The server returned an unexpected status code and no error class is registered for this code 400

Expected behavior

Either a more clear error code if there is a problem I'm not seeing, or no error after a successful upload.

How to reproduce

See code in first section.

SDK Version

1.17.0

Latest version known to work for scenario above?

No response

Known Workarounds

Ignoring the exception for error 400 works, but is not ideal.

Debug output

APIError
Code: 400
message: The server returned an unexpected status code and no error class is registered for this code 400

Configuration

Windows 11, x64. I haven't tested on any other systems at present.

Other information

This may not be related to the SDK at all, but if it is an error in the request that isn't clear from the documentation I've read on this. I will echo comments elsewhere that the documentation on using the SDK for uploads is extremely limited and I had to cobble a lot of this together from responses to other questions here.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 msgraph-sdk-python 1.17.0 重现 issue 中所示的上传,重点关注 LargeFileUploadTask.upload() 和报告的 APIError 400。检查请求周围的上传结果和错误处理,以确定为什么上传成功后仍会产生异常。当该行为得到解释,并且 SDK 能够适当地报告结果或记录所需的 workaround 时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。