Failed to run function : <class 'Exception'> : Dataset (name) is specified with a relative name

Solved!
rawan_mohammed
Level 2
Failed to run function : <class 'Exception'> : Dataset (name) is specified with a relative name

Hello, 

I'm working on a python function endpoint, and I need to call one of the datasets from the flow in the function.

however, when I try to run the test queries I get the following error: 

 Failed to run function : <class 'Exception'> : Dataset names is specified with a relative name, but no default project was found. Please use complete name

 

the code: 

def api_py_function(features):
    code = get_city_code(features["name"])
    return code

def get_city_code(name: str):
    dataset = dataiku.Dataset("names")
    df = dataset.get_dataframe()

Operating system used: Windows 11

0 Kudos
2 Solutions
FlorentD
Developer Advocate

Hi,

It seems that your endpoint is running outside the context of a project.  Then you should use:

project = client.get_project(<PROJECT_KEY>)
dataset = project.get_dataset(<NAME>)

 

Best

View solution in original post

nmadhu20

Hey @rawan_mohammed ,

Seems like you are accessing the dataset from outside DSS scope so in order to create the client object you would need to specifically point to the project.

import dataikuapi

host = "http://localhost:11200"
apiKey = "some_key"
client = dataikuapi.DSSClient(host, apiKey)
client._session.verify = False
project = client.get_project('project_name')

You can refer to the official doc for more details -  https://doc.dataiku.com/dss/latest/python-api/client.html?highlight=dssclient#dataikuapi.DSSClient

 

Hope this helps!

Regards,

Madhuleena

View solution in original post

6 Replies
FlorentD
Developer Advocate

Hi,

It seems that your endpoint is running outside the context of a project.  Then you should use:

project = client.get_project(<PROJECT_KEY>)
dataset = project.get_dataset(<NAME>)

 

Best

rawan_mohammed
Level 2
Author

Thank you! however can you tell me how to define the client? i tried all methods i found online but none of them seems to work.

and i'm running the method in the API Designer of the same project with the dataset. 

0 Kudos
FlorentD
Developer Advocate

Hi,

did you try this one:

 client = dataiku.api_client()

 

This is the usual way to get the client.

 

Best

0 Kudos
rawan_mohammed
Level 2
Author

I have but thanks again! the problem was actually the project key ๐Ÿ™‚  

0 Kudos
nmadhu20

Hey @rawan_mohammed ,

Seems like you are accessing the dataset from outside DSS scope so in order to create the client object you would need to specifically point to the project.

import dataikuapi

host = "http://localhost:11200"
apiKey = "some_key"
client = dataikuapi.DSSClient(host, apiKey)
client._session.verify = False
project = client.get_project('project_name')

You can refer to the official doc for more details -  https://doc.dataiku.com/dss/latest/python-api/client.html?highlight=dssclient#dataikuapi.DSSClient

 

Hope this helps!

Regards,

Madhuleena

rawan_mohammed
Level 2
Author

Thank you! this worked but apparently what i had wrong all that time were the api and project keys.

I was using the api key of the api i was working on, and my personal api key.

and the problem with the project key was that it should be capitalized ๐Ÿ™‚ 

Labels

?

Setup info

?
A banner prompting to get Dataiku