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

Client Error: 404 Client Error: Not Found for url: when switching between sharepoint and onedrive resources #1034

Open
ysguy opened this issue Dec 23, 2023 · 5 comments

Comments

@ysguy
Copy link

ysguy commented Dec 23, 2023

I have two python files, one calls a sharepoint doc library, attaches and reads an excel file. the other does the same for the onedrive associated with the azure application profile. I can read one but the other will get a 404 error. If i wait hours, and try the other with zero code changes it will work, but the other will break. It appears the client is somehow caching the site library URL.

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/me/drive/items/01SPB5GSZEZAQBYVNWDBAI7JVC3FTW3RKJ/workbook/createSession | Error Message: The resource could not be found.

I've seen others post similar messages that are years old now. It appears that the drive ID is not changing between requests.  

I can see the filename, and the search works and returns the correct file object, but it always dies at
od_excel_file = WorkBook(XLfile)

the XLfile reference works because i have code a line before it that prints out the name per your guide.

print(f'OneDrive Searched Files Found: {XLfile}')
Which returns 'myfile.xlsx'

Do i need to close session on the workbook object somehow? I see nothing in the docs about this.

@ysguy
Copy link
Author

ysguy commented Dec 23, 2023

Resolved. Thanks for being my Rubber Duckie. Changing my code to not persist immediately resolves it. Sorry for missing this important information.

The Fix:
od_excel_file = WorkBook(XLfile, use_session=False, persist=False)

@ysguy ysguy closed this as completed Dec 23, 2023
@ysguy ysguy reopened this Dec 23, 2023
@ysguy
Copy link
Author

ysguy commented Dec 23, 2023

Reopening issue. It works randomly, but a majority of the time it still gives the 404 error with the use_session and persist false values.

How to test. Make one python or two python scripts that attach to an excel on onedrive and sharepoint doc libraries. Call one, then the other. The error will appear.

@alejcas
Copy link
Member

alejcas commented Jan 8, 2024

Can I see the error messages? I don't know what's happening and I don't know If I will be able to fix it

@parkus83
Copy link

parkus83 commented Feb 5, 2024

Hello everyone, I have the same problem. I am trying to modify an Excel file on SharePoint, and I can access it using ysguy's workaround (od_excel_file = WorkBook(XLfile, use_session=False, persist=False). However, when I try to access the sheets, columns, or individual rows, it gives me this error again:

requests.exceptions.HTTPError: 404 Client Error: Not Found for the URL:
https://graph.microsoft.com/v1.0/me/drive/items/01GOIU2PSQMCWJ47LBVRA33LRPXUHQCGDK/workbook/worksheets/MIGRATION
Error Message: The resource could not be found.

if I check the link provided above I retrieve a weird token error:

{
error: {
code: "InvalidAuthenticationToken",
message: "Access token is empty.",
innerError: {
date: "2024-02-05T10:52:47",
request-id: "c989ec4f-1cf9-4c8b-9de0-92692a141602",
client-request-id: "c989ec4f-1cf9-4c8b-9de0-92692a141602"
}
}
}

ps: I have used the following method to authenticate my application. And it return the default_storage correctly.

def access_sharepoint_drive() -> Drive:
    """
    Access sharepoint drive
    :return: sharepoint drive
    """
    credentials = (os.environ.get("CLIENT_ID_SHAREPOINT"), os.environ.get("CLIENT_SECRET_SHAREPOINT"))

    account = Account(credentials)
    
    # used only for the first time
    # scopes = ['basic', 'Files.ReadWrite.All', 'Files.Read.All']
    # if account.authenticate(scopes=scopes):
    #   logging.info("Authenticated to sharepoint")

    storage = account.storage()

    return storage.get_default_drive()

@alejcas
Copy link
Member

alejcas commented Feb 28, 2024

Hi I don't have the time to investigate this atm.

If you want to, a good start are ms graph docs:

https://learn.microsoft.com/en-us/graph/api/resources/excel?view=graph-rest-1.0

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

No branches or pull requests

3 participants