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 摘要。