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'
Hi
Did you run through the 1st notebook? (1_Authentication.ipynb)
This is where the function to create the client is created and defined
Hi
for me it works fine if I run the code as it is originally in the notebook:
c = cauth.create_cognite_client()
Hi
for me it works fine if I run the code as it is originally in the notebook:
c = cauth.create_cognite_client()
Hi
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?
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.
Hi
Did you manage to solve the issue and complete the course?
Best regards,
Dilini
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.
Hi
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
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.