Office365-rest-python-client: AttributeError: 'ClientContext' object has no attribute '_auth_context'

Created on 8 Dec 2020  ·  10Comments  ·  Source: vgrem/Office365-REST-Python-Client

Hi @vgrem ,

I am still getting the error "AttributeError: 'ClientContext' object has no attribute '_auth_context'" when i try running the below code snippet. Please help in resolving

pip install Office365-REST-Python-Client
ctx_auth = AuthenticationContext(Sharepoint_SiteUrl)
ctx_auth.acquire_token_for_user(User, Sharepoint_Password)
ctx = ClientContext(Sharepoint_SiteUrl, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Authentication successful")

bug

All 10 comments

Hey!

how about to switch from AuthenticationContext.acquire_token_for_user :

ctx_auth = AuthenticationContext(Sharepoint_SiteUrl)
ctx_auth.acquire_token_for_user(User, Pass)
ctx = ClientContext(Sharepoint_SiteUrl, ctx_auth) 

to ClientContext.with_user_credentials method:

ctx = ClientContext(site_url).with_user_credentials(username,password)

Still no luck?

But I need to use the token instead of using credentials directly in the request.. so will the above code still use the tiken?

Regarding original error

"AttributeError: 'ClientContext' object has no attribute '_auth_context'" when i try running the below code snippet. Please help in resolving

indeed there was a bug with preserving AuthenticationContext instance while passing into ClientContext.

The _fixed_ version could be downloaded from GitHub:

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

Regarding

But I need to use the token instead of using credentials directly in the request.. so will the above code still use the tiken?

surely, behind the scene both ClientContext.with_user_credentials and AuthenticationContext.acquire_token_for_user are identical in terms of constructing authenticated request

Hi @vgrem
Iam using this code in databricks and we need to install the library at the cluster level.. there we do not have option of downloading from git...
When this new change ll be available as part of library?

No particular release date so far, but most likely by the end of this week.

@vgrem
It would be helpful if it is released by thus weekend.. next week is our lead testing for this code..
Meanwhile I will try the other code snippet the you mentioned.

I had another question. For client credentials, should the qpp with client id be registered in sharepoint online site or app should be registered in azure active directory?

Both options (SharePoint ACS & Azure AD) are supported.

@vgrem
Thanks for clarification

Was this page helpful?
0 / 5 - 0 ratings