microsoftgraph / microsoftgraph/msgraph-sdk-python

Error 400 during put on drive item

Open
#736 5 comments 0 reactions 1 assignee View on GitHub

@PrzemyslawSagalo is already working on this.

Since Jun 3, 2024.

Needs: Attention :wave: type:bug
Dominant language
Python
Stars
630
Forks
96
Avg merge
15h 20m
Merged PRs (30d)
3

Description

Describe the bug

I am trying to upload a .docx file into OneDrive using Graph API. Unfortunately, it returns an error 400.

msgraph.generated.models.o_data_errors.o_data_error.ODataError:
{
APIError
Code: 400
error: MainError(code='BadRequest', message='Entity only allows writes with JSON Content-Type header.')
}
Expected behavior

Based on the type from the code of the sdk passed type is correct, so I don't understand this behaviour and the bellow code should upload the file.

How to reproduce
file_path = "test.docx"
with open(file_path, "rb") as file_handle:
    file_bytes = file_handle.read()

item_path = "/root:/Documents/test_on_one_drive.docx"
r = await client.drives.by_drive_id(drive_id).items.by_drive_item_id(item_path).content.put(body=file_bytes)
SDK Version

1.4.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.