Error on client auth when calling function from CDF UI

Badge +6


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

In the 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 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 17 May 2023, 00:31

View original

5 replies

Badge +6

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




Userlevel 1

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.






Userlevel 1

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



Badge +6

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.




Userlevel 1

Sounds good. Thanks for your reply!