vgrem / Office365-REST-Python-Client

Microsoft 365 & Microsoft Graph Library for Python
MIT License
1.34k stars 336 forks source link

get_file_by_server_relative_path don't see the file #825

Open StefanoGITA opened 9 months ago

StefanoGITA commented 9 months ago

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 commented 9 months ago

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

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

StefanoGITA commented 9 months ago

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)

VictorReyesA commented 3 months ago

hi @StefanoGITA did you solve your question, i;m facing same issue with no solution :/