Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I have few Python codes which I have converted into modules by defining them under the "Python" folder present under the libraries section of my project.
These libraries are using some files from the managed folders of the project. I am accessing these folders in these modules by using
"folder = folders"
This has always worked for me. But now I am getting an error.
The script that is using these modules is to deployed as an API using the API designer.
Is there a way to fix this?
Operating system used: Windows
Could you please verify that all of the managed folders you're trying to access are set as working folders for the Python endpoint? You can add working folders under the endpoint settings:
You'll need to redeploy the service after adding any folders.
If this doesn't solve your issue, could you please provide the following information?
Yes, I had already added all my working folders in the API settings. But still it does not work.
This is the code which I want to deploy as an API.
import pandas as pd from my_custom_code import function_1 def main_api_function(some paramters): results = function_1(some_other_parameters) return results
This is the code which is being used as a module in the main code mentioned above
I have put this code under the "Libraries" section of my project.
I am getting an error in the line containing the folder path.
The error is as follows
Dev server deployment FAILED
Failed to initiate function server : "<class 'NameError'>" : name 'folders' is not defined
svc: my_api_service_name: in ep:my_api_service_name: Service my_api_service_name is not active
import pandas as pd folder_path = folders def function_1(some paramters): # some computations return something
The surprising part is that all of this works fine in Jupyter Notebooks and recipe.
Only while deploying the code as an API, I am getting such errors.
Apart from the folders, I did try things like the one mentioned below, but none of it is working
folder_path = dataiku.Folder("projectID.folderID").get_path()
folder_path = dataiku.Folder("folder_name").get_path()
Thank you for the additional information.
The reason that you're getting this error is that the folders variable is only available from the endpoint code. It isn't accessible from modules.
You can make it work by passing the folder_path as an argument to function_1, like this:
import pandas as pd from my_custom_code import function_1 folder_path = folders def main_api_function(some_paramters): results = function_1(folder_path, some_other_parameters) return results
import pandas as pd def function_1(folder_path, some_paramters): # do something with folder_path # some computations return something