Skip to content

Downloading or reading a JSON file from OneDrive #944

@anousias-k3y

Description

@anousias-k3y

I was working on a module for programmatically handling files from an onedrive folder and I get a weird JSON decode error specifically when downloading JSON files or in general attempting to get their content:

Expecting value: line 8 column 24 (char 216)
simplejson.errors.JSONDecodeError: Expecting value: line 8 column 24 (char 216)

It seems that, for some reason, before downloading, the client attempts to decode the file first (?).

I am following the corresponding example for downloading files:

drive_items = remote_folder.children.get_all().execute_query()
    
for drive_item in drive_items:

    if drive_item.file is None:
        continue
        
    # download file content
    local_path = os.path.join(local_folder, drive_item.name)

    with open(local_path, "wb") as local_file:
        drive_item.download(local_file).execute_query_retry()

I don't know if this is the same kind of error with #598 where I first commented. As a commenter mentioned there, if I manually rename the file with a different suffix, e.g. .jsn I can download the file with no problem.

Also I need to mention that the .json decode error probably originates due to some nan values encoded as NaN (default behavior of the python json library) which may raise an error with other libraries (simplejson) which are strict with rfc7159(?) and require to pass an argument such as allow_nan=True. Whatever the case, having to decode a .json file before downloading it, seems to me pretty irrelevant.

versions:

  • python==3.10
  • office365-rest-python-client==2.5.11

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions