microsoftgraph / microsoftgraph/msgraph-sdk-python

FileAttachment.content_bytes does not return b64-encoded content.

Offen
#1,556 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

status:waiting-for-triage type:bug
Vorherrschende Sprache
Python
Sterne
630
Forks
96
Ø Merge
15 Std. 20 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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_

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Feld content_bytes des Modells FileAttachment und dem Aufruf zum Abrufen des Anhangs in der Reproduktion. Vergleiche das Verhalten zwischen den SDK-Versionen 1.58.0 und 1.60.0 und führe anschließend die bereitgestellte b64decode-Validierung mit einem abgerufenen Anhang aus. Erledigt ist es, wenn content_bytes wie beschrieben mit validate=True an b64decode übergeben werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.