Skip to main content
Solved

Error in Learn to Use the Cognite Python SDK


Forum|alt.badge.img

Getting an error on 2_List_Search_Retrieve.ipynb:

c = cauth.create_cognite_client(method="client-secret")

AttributeError Traceback (most recent call last) c:\Users\tomas.kurten.perez\Downloads\COGNITE\using-cognite-python-sdk\notebooks\2_List_Search_Retrieve.ipynb Cell 7 in <cell line: 1>() ----> 1 c = cauth.create_cognite_client(method="client-secret") AttributeError: module 'auth' has no attribute 'create_cognite_client'

Best answer by Dilini Fernando

Hi @tomaskurtenperez,

I hope the above helped. I’m closing this thread now, please feel free to create a new post if you have any questions.

Best regards,
Dilini

 

View original
Did this topic help you find an answer to your question?

8 replies

Forum|alt.badge.img

Hi

Did you run through the 1st notebook? (1_Authentication.ipynb)
This is where the function to create the client is created and defined


Sofie Haug
Practitioner
Forum|alt.badge.img+7
  • Cognite Academy Instructor
  • 150 replies
  • February 28, 2023

Hi @tomaskurtenperez 

for me it works fine if I run the code as it is originally in the notebook:  

c = cauth.create_cognite_client()

 


Forum|alt.badge.img
Sofie Haug wrote:

Hi @tomaskurtenperez 

for me it works fine if I run the code as it is originally in the notebook:  

c = cauth.create_cognite_client()

 

Hi @Sofie Haug , i tried that way too, but it didn't work.
Also on the 1st notebook i got a problem with client.login.status()

CogniteAuthError: Error generating access token: invalid_client, 401, AADSTS7000216: 'client_assertion', 'client_secret' or 'request' is required for the 'client_credentials' grant type. Trace ID: 24b037b2-0788-4395-b5a6-5929b2878700 Correlation ID: 23d98b09-b4f2-44c3-8775-3e23826ae046 Timestamp: 2023-02-28 18:00:17Z

How can i resolve the problems? Can I continue with the training without using that functions? 


Forum|alt.badge.img

 Have a setup the secret in your local environment?

“Make Sure, You've created an environment variable CLIENT_SECRET with the value of the client secret obtained from admin.” 


There are multiple ways you can do that, either by using an .env file, you can get more information here 
You can also set the client secret using getpass, see more info here. The lines of code for that are in the notebook, but commented

 

The line to check if the client is connected should be

client.iam.token.inspect()

We will update the code on the notebook. 


Sofie Haug
Practitioner
Forum|alt.badge.img+7
  • Cognite Academy Instructor
  • 150 replies
  • February 28, 2023

@tomaskurtenperez you are depending on being able to authenticate towards CDF to be able to move on. 

@Gaetan Helness A client secret shouldn’t be necessary since in the #2 notebook, they authenticate with interactive log in (if I remember correctly)..


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+2

Hi @tomaskurtenperez ,

Did you manage to solve the issue and complete the course?

Best regards,
Dilini


Forum|alt.badge.img+1

Try using OAuth authentication method. 

 

from cognite.client import CogniteClient, ClientConfig

from cognite.client.credentials import OAuthClientCredentials

tenant = "xyz"
client_id = "xyz"
scope = "xyz"
cdf_cluster = "xyz"
client_secret = "xyz"
project_name="xyz"
base_url= f"https://{cdf_cluster}.cognitedata.com"
token_url= f"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token"

creds = OAuthClientCredentials(
    token_url=token_url,
    client_id=client_id,
    client_secret=client_secret,
    scopes=scope,
    )

cnf = ClientConfig(client_name="xyz", project=project_name, credentials=creds, base_url=base_url)
client = CogniteClient(cnf)

print(client.login.status())

 

fill in the environment details and this should work.


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+2
  • Seasoned Practitioner
  • 671 replies
  • Answer
  • March 24, 2023

Hi @tomaskurtenperez,

I hope the above helped. I’m closing this thread now, please feel free to create a new post if you have any questions.

Best regards,
Dilini

 


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings