Skip to content

400 Client Error: Bad Request for url when file path is too long #988

@achal648

Description

@achal648

Hi, I'm encountering a 400 Client Error: Bad Request when trying to move a file using move_to_using_path in SharePoint via the Office365 Python library.

The error seems to occur when the file path is too long. If I shorten the file name or folder structure, the move operation succeeds.

This appears similar to Issue 319, where using ODataUrlBuilder or ODataPathBuilder was suggested as a workaround. However, these utilities no longer seem to be available in the latest version of the library.

Is there any recommended workaround for this?

Environment:

  • Python version: 3.13
  • Office365-REST-Python-Client version: 2.6.1

Code Snippet:

file_from = ctx.web.get_file_by_server_relative_url(source_path)
file_to = file_from.move_to_using_path(destination_folder_path, MoveOperations.overwrite).execute_query()

Error Message:

400 Client Error: Bad Request for url: https://<your-sharepoint-site>/_api/Web/getFileByServerRelativeUrl('%2Fsites%2F<site-name>%2FShared%20Documents%2F<folder-path>%2F<filename>.xlsx')/MoveToUsingPath(DecodedUrl='%2Fsites%2F<site-name>%2FShared%20Documents%2F<destination-folder>%2F<filename>.xlsx',moveOperations=1)

Any help or guidance would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions