Error in Learn to Use the Cognite Python SDK

  • 27 February 2023
  • 8 replies


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 24 March 2023, 07:08

View original

8 replies

Userlevel 4


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

Userlevel 3
Badge +6

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

Userlevel 4

 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


We will update the code on the notebook. 

Userlevel 3
Badge +6

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

Userlevel 4
Badge +2

Hi @tomaskurtenperez ,

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

Best regards,

Badge +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"
base_url= f"https://{cdf_cluster}"
token_url= f"{tenant}/oauth2/v2.0/token"

creds = OAuthClientCredentials(

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



fill in the environment details and this should work.

Userlevel 4
Badge +2

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,