microsoftgraph / microsoftgraph/msgraph-sdk-python
FileAttachment.content_bytes does not return b64-encoded content.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 630
- Forks
- 96
- Merge medio
- 15 h 20 min
- PR fusionados (30 d)
- 3
Descripción
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_
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el campo content_bytes del modelo FileAttachment y la llamada de recuperación del archivo adjunto en la reproducción. Compara el comportamiento entre las versiones 1.58.0 y 1.60.0 del SDK y, después, ejecuta la validación proporcionada de b64decode con un archivo adjunto recuperado. Se considera terminado cuando content_bytes se puede pasar a b64decode con validate=True, tal como se describe.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100