Skip to main content
Solved

Error on client auth when calling function from CDF UI


Forum|alt.badge.img+6

Hello! 

I've created a function with the CDF UI using a zip file containing the handler.py file and requirements.txt.

In the handler.py file I have some imports for the cognite.client and pandas, then some data wrangling using client.assets and then the handle function.

I don't have the login code for the cognite client within the code in handler.py as I've understood that is not needed on runtime.

When calling the function from CDF UI, I receive the error related to the "client" as it doesn't recognizes it.

 

Should I provide an .env file within the zip file along with the code for instantiating the CogniteClient()? Or provide the needed env vars as secrets when creating the function from UI?

 

Thank you

Best answer by Raluca Bala

Nevermind, I've solved it with .env file, config.yaml and creating the CogniteClient() inside handler.py.

 

Thanks,

Raluca

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

5 replies

Forum|alt.badge.img+6
  • Author
  • Seasoned
  • 16 replies
  • Answer
  • May 16, 2023

Nevermind, I've solved it with .env file, config.yaml and creating the CogniteClient() inside handler.py.

 

Thanks,

Raluca


dinesh.makked
Seasoned

You have solved the problem but it is not the best approach. You don’t need to neither instantiate the client not use the config or env file.

 

Based on the error “client is not defined”, I am thinking that you are not passing the “client” as the first argument for the function hence the error.

You should have two parameters for you function.

  1. client
  2. data 

The client parameter automatically gets passed to the function by the wrapper program and you don’t need to do anything except use it inside your function. 
 

The second parameter is used to pass other function-specific parameters.

 

Please let me know if this resolves the issue otherwise I can provide further guidance.

 

Thx

Dinesh

 

 


dinesh.makked
Seasoned

@Raluca Bala I want to make sure that you saw my message. My concern is that you are missing the fundamental understanding of Cognite Functions and I would like to fill the gap. If you would like to chat more about it, please let me know and we can get in a meeting.

Thanks

Dinesh


Forum|alt.badge.img+6
  • Author
  • Seasoned
  • 16 replies
  • May 19, 2023

Hi @dinesh.makked ,

Thank you for your answer, but initially this was how I've uploaded my function and tried to run it with the 2 parameters (client, data) . It throws the error I printed in the first post. I don't pass anything for data as it's not needed.

I've gone through all the examples for function in documentation and in cognitedata repos so I think I've tried to use it as understood from materials.

It may be related to specific rights in CDF? I am able to create and run the function so it wouldn't be this.

 

Regards,

Raluca


dinesh.makked
Seasoned

Sounds good. Thanks for your reply!


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