Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharepoint - "404 Client Error: Not Found for url" When try download file with # in name #505

Closed
JLTs66 opened this issue May 8, 2022 · 3 comments

Comments

@JLTs66
Copy link

JLTs66 commented May 8, 2022

Sharepoint Office 365 (online). Try to use method download_session, work normally except when "#" caract in the name. The code raise :
office365.runtime.client_request_exception.ClientRequestException: ('-2130575338, Microsoft.SharePoint.SPException', "Le fichier /personal/user_test_ca/Documents/File with#.doc n'existe pas.", "404 Client Error: Not Found for url: https://mycon.sharepoint.com/personal/user_test_ca/_api/Web/getFileByServerRelativeUrl('%2Fpersonal%2Fuser_test_ca%2FDocuments%2FFile with%23.doc')?$select=ServerRelativeUrl")

To repeat the problem, just put file with a .doc with a hash (#) in the name, and download it with the method "download_session".

Exemple code :

source_file = ctxSrc.web.get_file_by_server_relative_url(props["ServerRelativeUrl"])
with open(os.path.join(temp_dir,name), "wb") as local_file:
    source_file.download_session(local_file, print_download_progress).execute_query()

Note : I try with replacement of "get_file_by_server_relative_url" by "get_file_by_id" (with UniqueID), same issue.

End of the error tracestack :

  File "copyStoS.py", line 167, in copyFolder
    source_file.download_session(local_file, print_download_progress).execute_query()
  File "...\lib\site-packages\office365\runtime\client_object.py", line 41, in execute_query
    self.context.execute_query()
  File "...\lib\site-packages\office365\runtime\client_runtime_context.py", line 134, in execute_query
    self.pending_request().execute_query()
  File "...\lib\site-packages\office365\runtime\client_request.py", line 84, in execute_query
    raise ClientRequestException(*e.args, response=e.response)
@JLTs66
Copy link
Author

JLTs66 commented May 10, 2022

Same problem when % in name (same that #)

@JLTs66
Copy link
Author

JLTs66 commented May 10, 2022

I discover that the module will always use "GetFileByServerRelativeUrl" in url call. Even if we use "get_file_by_id" just before.

Maybe it's possible to force the module to not use GetFileByServerRelativeUrl when we download/moveto/etc...

@vgrem
Copy link
Owner

vgrem commented Oct 18, 2022

Hi there,

the root cause why this error occurs in the first place is related with internals of server side getFileByServerRelativeUrl method implementation and summarized in Supporting % and # in files and folders with the ResourcePath API:

Support for % and # in files and folders is being deployed within SharePoint Online. Unfortunately, due to existing API structures and calling patterns, working with these file names can sometimes become ambiguous.

Resolution

Prefer Web.get_file_by_server_relative_path over Web.get_file_by_server_relative_url method which supports those symbols in file name. As of File.download_session method, starting from 2.3.13 version it uses path based addressing as well by default.

Related issues: #486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants