Skip to content

fix: handle JSON file download from OneDrive /content endpoint#1023

Open
vgrem wants to merge 3 commits into
masterfrom
fix/onedrive-json-download
Open

fix: handle JSON file download from OneDrive /content endpoint#1023
vgrem wants to merge 3 commits into
masterfrom
fix/onedrive-json-download

Conversation

@vgrem

@vgrem vgrem commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Description

Fixes downloading .json files from OneDrive via DriveItem.download().

Problem

The OData response processor in process_response() relies solely on the Content-Type header to decide whether to parse the body as OData JSON or return raw bytes. When downloading a .json file from OneDrive, the Graph /content endpoint returns application/json, causing the client to parse the file contents as an OData response instead of returning raw bytes.

The SharePoint $value endpoint doesnt have this issue because it returns application/octet-stream.

Fix

Added _is_content_download() static method that checks if the query is a FunctionQuery named "content" (OneDrive) or "$value" (SharePoint) — these always represent raw file content. When true, the response body is returned as raw bytes regardless of Content-Type.

Changes

  • office365/runtime/odata/request.py: 11 insertions, 1 deletion

Fixes #944, #598

Testing

  • OneDrive download of .json files
  • OneDrive download of .txt, .csv, .bin files (should continue working)
  • SharePoint download via $value (should continue working)

Vadim Grem added 3 commits June 18, 2026 12:09
The OData response processor relies solely on Content-Type header to decide
whether to parse the response body as OData JSON. For OneDrive's /content
endpoint, a .json file returns application/json, causing the client to
incorrectly parse the file contents as an OData response instead of
returning raw bytes.

Fix: add _is_content_download() check that skips JSON parsing for
FunctionQuery operations named 'content' (OneDrive) or '$value' (SharePoint),
which always represent raw file content downloads.

Fixes #944, #598
Replace _is_content_download name matching with a explicit
return_raw_content flag on FunctionQuery. Callers set the flag
at construction time — cleaner and extensible.
Replace getattr hack in _is_content_download with a proper
isinstance + property check directly on the query object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downloading or reading a JSON file from OneDrive

1 participant