How to handle exceptions in Execute Python Script

Hello,

I have a simple workflow with two “Execute Python Script” steps.
In the first, a list called data is created with some integers and in the second Python Script I am iterating through the list, applying a mathematical operation to each element in the list.

But when I run this workflow for the first time, I get an error “NameError: name ‘data’ is not defined” in the second Execute Python Script. The variable data is defined in first Execute Python Script.
When I run this workflow again, for the second time, it runs without any error.

Is this the expected behavior? Is there any way to run this workflow without errors everytime?

How can I catch this and another exceptions to handle externally, if Execute Python Script step does not have an Error handling hop?

First Execute Python Script code:

# python script

data = [1, 2, 3, 4, 5]

Second Execute Python Script code:

# python script

squared_data = []

for item in data:
    squared_data.append(item*item)

The error message:

2020/03/13 11:02:50 - AutomationEdge Process Studio - Launching workflow [squared_list]...
2020/03/13 11:02:50 - AutomationEdge Process Studio - Started the workflow execution.
2020/03/13 11:02:51 - squared_list - Dispatching started for workflow [squared_list]
2020/03/13 11:02:52 - Execute Python Script 2.0 - ERROR (version 5.3.1 from 2019-08-30) : Unexpected error
2020/03/13 11:02:52 - Execute Python Script 2.0 - ERROR (version 5.3.1 from 2019-08-30) : com.automationedge.ps.core.exception.ProcessStudioException: 
2020/03/13 11:02:52 - Execute Python Script 2.0 - Traceback (most recent call last):
  File "C:\Users\Israel\AppData\Local\Temp\pyServer.py", line 299, in execute_script
    exec (script, _global_env)
  File "<string>", line 5, in <module>
NameError: name 'data' is not defined

2020/03/13 11:02:52 - Execute Python Script 2.0 - 
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at com.automationedge.ps.workflow.steps.pythonscript.PythonScript.executeScript(PythonScript.java:450)
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at com.automationedge.ps.workflow.steps.pythonscript.PythonScript.executeScriptAndProcessResult(PythonScript.java:347)
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at com.automationedge.ps.workflow.steps.pythonscript.PythonScript.processBatch(PythonScript.java:336)
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at com.automationedge.ps.workflow.steps.pythonscript.PythonScript.processRow(PythonScript.java:241)
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at com.automationedge.ps.workflow.step.RunThread.run(RunThread.java:68)
2020/03/13 11:02:52 - Execute Python Script 2.0 - 	at java.lang.Thread.run(Unknown Source)
2020/03/13 11:02:52 - Execute Python Script 2.0 - Finished processing (I=0, O=0, R=0, W=0, U=0, E=1)
2020/03/13 11:02:52 - squared_list - Workflow detected one or more steps with errors.
2020/03/13 11:02:52 - squared_list - Workflow is killing the other steps!
2020/03/13 11:02:52 - squared_list - ERROR (version 5.3.1 from 2019-08-30) : Errors detected!
2020/03/13 11:02:52 - AutomationEdge Process Studio - The workflow has finished!!
2020/03/13 11:02:52 - squared_list - ERROR (version 5.3.1 from 2019-08-30) : Errors detected!
2020/03/13 11:02:52 - squared_list - ERROR (version 5.3.1 from 2019-08-30) : Errors detected!

Hi,

Workflow should execute every time when script is correct.
I tried the same script as mentioned by you and workflow executed correctly all the times.
See the following screen shots for steps and workflow.
1)
image

image

I hope it helps.

@israelvf I Believe that your WF is missing that Generate Rows before the Python steps.

Hi,

When I try to run python script step (Simple script only) it is showing java.lang.NullPointerException. but if I run the same WF from AE portal through Agent, it’s working.

And I am unable to run python script in any other workflows also.

Could you please help me in solving this?

Thanks,
Ramesh

Hi @Ramesh17 please check if you have changed the number of rows to be generated by the Generate Rows from 10 to 1, otherwise, it will send 10 rows to be executed in the Python step… and that might be the reason for the error.