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

get_file_by_server_relative_path don't see the file #825

Open
StefanoGITA opened this issue Feb 14, 2024 · 2 comments
Open

get_file_by_server_relative_path don't see the file #825

StefanoGITA opened this issue Feb 14, 2024 · 2 comments
Labels

Comments

@StefanoGITA
Copy link

StefanoGITA commented Feb 14, 2024

I find an issue when I try to use the method get_file_by_server_relative_path of this lib (Office365-REST-Python-Client]).
The connection to the sharepoint goes well, but when i try to get a file that I'm sure that is there, I get this error:

_office365.runtime.client_request_exception.ClientRequestException: ('-2130575338, Microsoft.SharePoint.SPException', 'Il file /sites/*******/_SALVA_APPOGGIO_OA/progettoOA.zip non esiste.', "404 Client Error: Not Found for url: https://*********.sharepoint.com/_api/Web/getFileByServerRelativePath(DecodedUrl='%2F*****%2F*******%2F*******%2F*******%2F_SALVA_APPOGGIO_OA%2FprogettoOA.zip')")

I used the code of the example reported on the lib (see lower), so I don't understand because the lib don't find the file that (as I wrote) I'm sure that exists in that path.

Someone can help me?
Thanks.

def test_w_sp_py_lib(site_url, file_path, username, password):
    from office365.sharepoint.client_context import ClientContext   # , UserCredential
    import tempfile

    ctx = ClientContext(site_url).with_user_credentials(username, password)
    web = ctx.web.get().execute_query()
    print(web.url)

    file = ctx.web.get_file_by_server_relative_path(file_path).get().execute_query()
    print("File size: ", file.length)
    print("File name: ", file.name)
    print("File url: ", file.serverRelativeUrl)

    # download_path = Path(tempfile.mkdtemp()).joinpath(Path(file_path).name)
    # with open(download_path, "wb") as local_file:
    #     file = (
    #         ctx.web.get_file_by_server_relative_url(file_path)
    #         .download(local_file)
    #         .execute_query()
    #     )
    #     print(
    #         f"'{file.server_relative_path}' file has been downloaded into {local_file.name}"
    #     )
@Danxx26hub
Copy link

Danxx26hub commented Feb 15, 2024

In sharepoint “server relative path” should look like this:

“https.{domain/tenant}.sharepoint.com” {server relative}—> /sites/{site name}

@StefanoGITA
Copy link
Author

In sharepoint “server relative path” should look like this:

“https.{domain/tenant}.sharepoint.com” {server relative}—> /sites/{site name}

Hi @Danxx26hub
On documentatio: https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/files/download.py the path is show in this way:

file_url = "Shared Documents/big_buck_bunny.mp4"
# file_url = "Shared Documents/!2022/Financial Sample.xlsx"

Also show on description of the method: Office365-REST-Python-Client/office365/sharepoint/webs
/web.py

And how You ca see from the error that i put on issue my path start with /sistes: "/sites/*******/_SALVA_APPOGGIO_OA/progettoOA.zip" (obviously the starts are putted by me to don't show th real path)

@vgrem vgrem added the question label Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants