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

404 when trying to read a file from sharepoint #583

Open
andreas789 opened this issue Oct 20, 2022 · 2 comments
Open

404 when trying to read a file from sharepoint #583

andreas789 opened this issue Oct 20, 2022 · 2 comments
Labels

Comments

@andreas789
Copy link

andreas789 commented Oct 20, 2022

I am trying to read some files from a SharePoint 365 location using the office-365 python rest API. I created an app principal and used it to get the files.

I am able to list the directory using the code below, so I have no problem authenticating.

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential
from office365.sharepoint.files.file import File
import io
import pandas as pd

site_url = 'https://*.sharepoint.com/sites/sharepoint_to_dbfs/'

app_principal = {
'client_id': '*',
'client_secret': '*',
}

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_app(client_id=app_principal['client_id'], client_secret=app_principal['client_secret']):
    ctx = ClientContext(site_url, ctx_auth)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()
    print('Authenticated into sharepoint app for: ',web.properties['Title'])
    lists = ctx.web.lists
    ctx.load(lists)
    ctx.execute_query()
    for l in lists:
        print("This is a list object: {0}".format(l.properties['Title']))
    list_object = ctx.web.lists.get_by_title('Documents')
    items = list_object.items
    ctx.load(items)
    ctx.execute_query()
    for l in items:
        print("This is a item object: {0}".format(l.properties['Title']))

else:
    print(ctx_auth.get_last_error())

However, when trying to get an excel file loaded onto a pandas df I am getting an error.

file_url = "/sites/sharepoint_to_dbfs/Test/Book.xlsx"

response= File.open_binary(ctx, file_url)
    # save data to BytesIO stream
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)  # set file object to start
    # load Excel file from BytesIO stream
df = pd.read_excel(bytes_file_obj, engine='openpyxl')

The error is:

File is not a zip file.

When checking the response I got, I see a 404 error and the following content. The file however exists on that path.

b'{"error":{"code":"-2130575338, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The file /sites/sharepoint_to_dbfs/Test/Book.xlsx does not exist."}}}'
@andreas789 andreas789 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2022
@andreas789
Copy link
Author

Any clues on how to solve that?

@andreas789 andreas789 reopened this Oct 26, 2022
@vgrem vgrem added the question label Oct 28, 2022
@Zangetsu89
Copy link

same issue

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