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 Client Error - User cannot be found #895

Open
z4ndr3i opened this issue Sep 19, 2024 · 0 comments
Open

404 Client Error - User cannot be found #895

z4ndr3i opened this issue Sep 19, 2024 · 0 comments
Labels

Comments

@z4ndr3i
Copy link

z4ndr3i commented Sep 19, 2024

As of version 2.5.8 I am getting an error when attempting to check if a user exists in SharePoint Online. This does not occur in v2.5.7.

I included below the function with the "user_name" parameter, which receives an argument of type string in UPN format (e.g. [email protected]) when called.

Function:

"""
CHECK USER
"""
def ensure_user_exists(user_name):

    #Ensure user exists and obtain its Id
    user = ctx.web.ensure_user(user_name)
    ctx.load(user)
    ctx.execute_query()
    user_id = user.properties['Id']
    return user_id

Exception:

Traceback (most recent call last):
File "/code/lib/python3.10/site-packages/office365/runtime/client_request.py", line 38, in execute_query
response.raise_for_status()
File "/code/lib/python3.10/site-packages/requests/models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: for url: https://mytenant.sharepoint.com/sites/MySite/_api/Web/siteUsers(6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/code/myApp.py", line 254, in
execute_main_function()
File "/code/myApp.py", line 190, in execute_main_function
assigned_by_user_id = ensure_user_exists(assigned_by)
File "/code/myApp.py", line 180, in ensure_user_exists
ctx.execute_query()
File "/code/lib/python3.10/site-packages/office365/runtime/client_runtime_context.py", line 173, in execute_query
self.pending_request().execute_query(qry)
File "/code/lib/python3.10/site-packages/office365/runtime/client_request.py", line 42, in execute_query
raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('-1, Microsoft.SharePoint.Client.ResourceNotFoundException', 'User cannot be found.', '404 Client Error: for url: https://mytenant.sharepoint.com/sites/MySite/_api/Web/siteUsers(6)')

Again, this only happens in v2.5.8 and above. I can successfully execute my code with version 2.5.7 using the exact same parameters.

Any pointers or assistance would be appreciated.

@vgrem vgrem added the question label Nov 28, 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

2 participants