microsoftgraph / microsoftgraph/msgraph-sdk-python

FileAttachment.content_bytes does not return b64-encoded content.

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

还没有人认领这个 Issue。

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

描述

Describe the bug

On attempt to b64decode the content_bytes of a file attachment the following error occurs:
binascii.Error: Only base64 data is allowed
The same test provided below passes with msgraph-sdk <= 1.58.0
The code comments still suggest b64-encoded content:

# The base64-encoded contents of the file.
content_bytes: Optional[bytes] = None
Expected behavior

FileAttachment.content_bytes returns b64-encoded data.

How to reproduce
from base64 import b64decode
from typing import cast

from azure.core.credentials import TokenCredential
from azure.identity import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.attachment import Attachment
from msgraph.generated.models.file_attachment import FileAttachment
from settings import settings

credentials = cast(
    TokenCredential,
    ClientSecretCredential(
        tenant_id=settings().microsoft_graph_tenant_id,
        client_id=settings().microsoft_graph_client_id,
        client_secret=settings().microsoft_graph_client_secret,
    ),
)
scopes = ["https://graph.microsoft.com/.default"]
client = GraphServiceClient(credentials, scopes)


async def get_mail_attachments(
    mailbox: str, mail_id: str
) -> list[Attachment]:
    response = (
        await client.users.by_user_id(mailbox)
        .messages.by_message_id(mail_id)
        .attachments.get()
    )
    attachments: list[Attachment] = response.value or []
    return attachments


async def test_attachments():
    attachments = await get_mail_attachments("my-mailbox", "my-mail-id")
    assert len(attachments) >= 1
    first_attachment = attachments[0]
    assert isinstance(first_attachment, FileAttachment)
    b64decode(first_attachment.content_bytes, validate=True)

SDK Version

1.60.0

Latest version known to work for scenario above?

1.58.0

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 FileAttachment 模型的 content_bytes 字段以及复现中的附件检索调用开始。比较 SDK 版本 1.58.0 和 1.60.0 之间的行为,然后对检索到的附件运行提供的 b64decode 验证。完成的标准是:按照描述,content_bytes 可以在 validate=True 的情况下传递给 b64decode。

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

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

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