Description
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.