Error: type object 'UDF' has no attribute 'from_file'

Hey

We’ve tried to run this jupyternotebook where we have the UDF but when we reach the cell process = openeo.UDF.from_file("UDF/hillshade_UDF.py", runtime="Python") it complains about: **AttributeError** : type object 'UDF' has no attribute 'from_file'.

We followed an example (udf = openeo.UDF.from_file("udf-code.py")) from here: User-Defined Functions (UDF) explained — openEO Python Client 0.15.0a1 documentation but it does not work in our case.

Hi Andrea, could you check if you are using the latest version of the openeo python client?

You could check via:

import openeo
openeo.__version__

The latest version is 0.14.1. To update it via pip use

pip install openeo --upgrade

Thanks Michele, I have upgraded to ‘0.14.1’ version but I cannot connect to the openeo backend connection = openeo.connect("openeo.cloud").authenticate_oidc().

Error message:

Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?da81b344-caa4-4369-8d1f-e17825b89a56)

**---------------------------------------------------------------------------** **error** Traceback (most recent call last) **a:\ANSU\6_Tasks\2204_WorldWater_TBX\JupyterNotebook\Examples\Github_hillshade\hillshade-UDF-example.ipynb Cell 4** in <cell line: 1>**()** **----> [1](vscode-notebook-cell:/a%3A/ANSU/6_Tasks/2204_WorldWater_TBX/JupyterNotebook/Examples/Github_hillshade/hillshade-UDF-example.ipynb#X15sZmlsZQ%3D%3D?line=0)** connection = openeo.connect("openeo.cloud").authenticate_oidc() File **~\Anaconda3\envs\openeo\lib\site-packages\openeo\rest\connection.py:565**, in Connection.authenticate_oidc**(self, provider_id, client_id, client_secret, store_refresh_token, use_pkce)** 557 provider_id, client_info = self._get_oidc_provider_and_client_info( 558 provider_id=provider_id, client_id=client_id, client_secret=client_secret, 559 default_client_grant_check=lambda grants: ( 560 _g.REFRESH_TOKEN in grants and (_g.DEVICE_CODE in grants or _g.DEVICE_CODE_PKCE in grants) 561 ) 562 ) 564 # Try refresh token first. **--> 565** refresh_token = self._get_refresh_token_store().get_refresh_token( 566 issuer=client_info.provider.issuer, 567 client_id=client_info.client_id 568 ) 569 if refresh_token: 570 try: File **~\Anaconda3\envs\openeo\lib\site-packages\openeo\rest\auth\config.py:211**, in RefreshTokenStore.get_refresh_token**(self, issuer, client_id)** 210 def get_refresh_token(self, issuer: str, client_id: str) -> Union[str, None]: **--> 211** return self.get(_normalize_url(issuer), client_id, "refresh_token", default=None) File **~\Anaconda3\envs\openeo\lib\site-packages\openeo\rest\auth\config.py:113**, in PrivateJsonFile.get**(self, default, *keys)**

...

392 win_get_user_type(ace[2], sids), 393 object_type) 395 return mode **error**: (1332, 'LookupAccountSid', 'No mapping between account names and security IDs was done.')

The previous version does not provide this problem.

Did you try to specify the identity provider? For me this works fine:

connection = openeo.connect("openeo.cloud").authenticate_oidc("egi")

I did it.

Could you try to delete the old authentication token and authenticate again?

To find the path you can use in a command line

openeo-auth paths

or in a jupyter cell:

!openeo-auth paths

and then remove the file using:

rm REFRESH_TOKEN_PATH

here is the corresponding documentation:
https://open-eo.github.io/openeo-python-client/auth.html#auth-config-files-and-openeo-auth-helper-tool

1 Like

Thanks it works now!

:+1:

FYI: If you are working in a notebook context, you can easily remove the refresh token file with this python snippet too:

from openeo.rest.auth.config import RefreshTokenStore
RefreshTokenStore().remove()

also see Authentication and Account Management — openEO Python Client 0.15.0a1 documentation

2 Likes