Getting local variable in python
Hi,
I am trying to create a python script which will bring local variable defined in the project. Then I want to update that local variable in runtime automatically.
So for that i tried to use get_variable() function but facing the below error.Is it due to permission problem or anything else?
Would like answer on the below points:
1.Need to get the local variable which is defined.
2.How to update the local variable again in the python script? If you could share some sample code, that would help me
project = client.get_project("MYPROJECT")
variables = project.get_variables()
Error:
DataikuExceptionTraceback (most recent call last) <ipython-input-36-2b18e5e67dd1> in <module>() ----> 1 variables = project.get_variables() /app/dataiku/dataiku-dss-8.0.2/python/dataikuapi/dss/project.pyc in get_variables(self) 801 """ 802 return self.client._perform_json( --> 803 "GET", "/projects/%s/variables/" % self.project_key) 804 805 def set_variables(self, obj): /app/dataiku/dataiku-dss-8.0.2/python/dataikuapi/dssclient.pyc in _perform_json(self, method, path, params, body, files, raw_body) 1010 1011 def _perform_json(self, method, path, params=None, body=None,files=None, raw_body=None): -> 1012 return self._perform_http(method, path, params=params, body=body, files=files, stream=False, raw_body=raw_body).json() 1013 1014 def _perform_raw(self, method, path, params=None, body=None,files=None, raw_body=None): /app/dataiku/dataiku-dss-8.0.2/python/dataikuapi/dssclient.pyc in _perform_http(self, method, path, params, body, stream, files, raw_body) 1001 except ValueError: 1002 ex = {"message": http_res.text} -> 1003 raise DataikuException("%s: %s" % (ex.get("errorType", "Unknown error"), ex.get("message", "No message"))) 1004 1005 def _perform_empty(self, method, path, params=None, body=None, files = None, raw_body=None): DataikuException: com.dataiku.dip.exceptions.UnauthorizedException: Failed to read project permissions
Thanks,
Vinothkumar M
Best Answer
-
Marlan Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Dataiku Frontrunner Awards 2021 Participant, Neuron 2023 Posts: 319 Neuron
Answers
-
Thanks Marlan. Worked perfectly.
Just few follow up question reg the same topic.
When I should use Local and global variable?
Ex:In every run, i have to find a path from the file and use that in the next flow to access files in that path.
So in this case, which variable i should use?
As of now i defined global variable and it worked as expected.
-
Marlan Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Dataiku Frontrunner Awards 2021 Participant, Neuron 2023 Posts: 319 Neuron
Hi @Vinothkumar
,Glad to hear it worked. Re global vs local variables, I assume you are referring to the variable definition screen. I only use local variables if I'm going to deploy a project to an automation instance of DSS and I want to override a global variable during development.
For example, I sometimes use a variable for the list of addresses to send an error email to (via the Scenario reporter functionality). In Global variables (on the Design instance) I set that to the list of people I will want to send errors once the project is deployed to the automation instance. However, I also set a local variable (of the same name) to just me. This overrides the global variable so only I get the emails during development. Once the project is deployed to automation the global variable is used (since it's not overridden there) and emails are sent to the broader list.
Hope that helps.
Marlan
-
Thanks Marlan.Got the purpose of these 2 variable. Will use accordingly