404 Client Error - User cannot be found
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
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.