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

AttributeError: 'ClientContext' object has no attribute '_auth_context' #303

Closed
spurthikaribasaiah opened this issue Dec 8, 2020 · 10 comments
Labels

Comments

@spurthikaribasaiah
Copy link

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")

@vgrem
Copy link
Owner

vgrem commented Dec 8, 2020

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?

@vgrem vgrem added the bug label Dec 8, 2020
@spurthikaribasaiah
Copy link
Author

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

@vgrem
Copy link
Owner

vgrem commented Dec 8, 2020

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

@vgrem
Copy link
Owner

vgrem commented Dec 8, 2020

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

@spurthikaribasaiah
Copy link
Author

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?

@vgrem
Copy link
Owner

vgrem commented Dec 8, 2020

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

@spurthikaribasaiah
Copy link
Author

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

@spurthikaribasaiah
Copy link
Author

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?

@vgrem
Copy link
Owner

vgrem commented Dec 8, 2020

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

@vgrem vgrem closed this as completed Dec 8, 2020
@spurthikaribasaiah
Copy link
Author

@vgrem
Thanks for clarification

vgrem pushed a commit that referenced this issue Dec 13, 2020
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