{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: error_type: error_description"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Possible causes
The Python Script policy can
throw several different types of ScriptEvaluationFailed errors. The sections below describe some of these errors.
NameError
If there is a variable in the PythonScript code which is referenced or operated on without being defined, then you get the Name error.
Error response body
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "NameError:variable_nameisnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Example error response body
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnosis
Identify the PythonScript policy and the undefined variable name from the faultstring element of the error response. For example, in the following faultstring, the PythonScript name is myscript.py and the undefined variable name is num3:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Examine the PythonScript source file identified in step #1 above and verify if the undefined variable identified in step #1 above is being referenced. For example, the following PythonScript code references the undefined variable num3, which matches the faultstring:
num1=1.5num2=6.3sum=float(num1)+float(num3)print('The sum of {0} and {1} is {2}'.format(num1,num3sum))
Check if the specific variable is defined within the PythonScript code. If the variable is not defined, then that's the cause for the error.
In the example script shown above, the variable num3 is undefined. Therefore, you will get the below error:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Resolution
Ensure that all the variables referenced in the PythonScript code are properly defined.
To fix the issue with the example PythonScript shown above, define the variable num3 before using it. For example:
num1=1.5num2=6.3num3=8.7sum=float(num1)+float(num3)print('The sum of {0} and {1} is {2}'.format(num1,num3,sum))
ZeroDivisionError
This error is raised when the second argument of a division or modulo operation is zero.
Error response body
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "ZeroDivisionError:reason_for_error"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Example error response body
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnosis
Identify the PythonScript policy name and the reason for failure from the faultstring element of the error response. For example, in the following faultstring, the PythonScript name is myscript.py and the reason for failure is integer division or modulo by zero:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Examine the PythonScript source file identified in step #1 above and verify if there's a division or a modulus operation by zero. For example, the following PythonScript code performs division by zero, which matches with what's in the faultstring:
a=0b=5c=b/aprintc
In the example script shown above, because the second argument of the division operation is zero, you get the following error:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Resolution
Ensure that the second argument of a division or modulo operation is non zero in the PythonScript.
To fix the issue with the example PythonScript shown above, use a non zero value as the second argument of a division or modulo operation. For example:
a=3b=5c=b/aprintc
More Information
There are many other possible causes for the error steps.script.ScriptEvaluationFailed apart from the ones described above. Please refer to the official Python documentation for more information.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003eThis documentation focuses on troubleshooting \u003ccode\u003eScriptEvaluationFailed\u003c/code\u003e errors in Apigee and Apigee hybrid PythonScript policies.\u003c/p\u003e\n"],["\u003cp\u003eA common cause of the \u003ccode\u003eScriptEvaluationFailed\u003c/code\u003e error is \u003ccode\u003eNameError\u003c/code\u003e, which occurs when a variable is referenced in the PythonScript without being defined, this section explains how to diagnose and resolve the error.\u003c/p\u003e\n"],["\u003cp\u003eAnother common cause of this error is \u003ccode\u003eZeroDivisionError\u003c/code\u003e, which happens when a division or modulo operation attempts to divide by zero, and explains how to identify and resolve this.\u003c/p\u003e\n"],["\u003cp\u003eThe document provides concrete examples of error response bodies and shows how to diagnose each, in addition to showing how the errors can be resolved.\u003c/p\u003e\n"]]],[],null,["*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/troubleshoot/policies/runtime/python-script-runtime-errors) documentation.*\n| **Note:** Was this troubleshooting playbook helpful? Please let us know by clicking [Send Feedback]().\n\nScriptEvaluationFailed\n\nError code \n\n steps.script.ScriptEvaluationFailed\n\nError response body \n\n```python\n{\n \"fault\": {\n \"faultstring\": \"Evaluation of script \u003cvar translate=\"no\"\u003epythonscript_name\u003c/var\u003e (py) failed with reason: \u003cvar translate=\"no\"\u003eerror_type\u003c/var\u003e: \u003cvar translate=\"no\"\u003eerror_description\u003c/var\u003e\"\",\n \"detail\": {\n \"errorcode\": \"steps.script.ScriptEvaluationFailed\"\n }\n }\n}\n```\n\nPossible causes\n\nThe [Python Script](/apigee/docs/api-platform/reference/policies/python-script-policy) policy can\nthrow several different types of `ScriptEvaluationFailed` errors. The sections below describe some of these errors.\n\nNameError\n\nIf there is a variable in the PythonScript code which is referenced or operated on without being defined, then you get the Name error.\n\nError response body \n\n```python\n{\n \"fault\": {\n \"faultstring\": \"Evaluation of script \u003cvar translate=\"no\"\u003epythonscript_name\u003c/var\u003e (py) failed with reason: \"NameError: variable_name is not defined\"\",\n \"detail\": {\n \"errorcode\": \"steps.script.ScriptEvaluationFailed\"\n }\n }\n}\n```\n\nExample error response body \n\n```python\n{\n \"fault\": {\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"NameError: 'num3' is not defined\"\",\n \"detail\": {\n \"errorcode\": \"steps.script.ScriptEvaluationFailed\"\n }\n }\n}\n```\n\nDiagnosis\n\n1. Identify the PythonScript policy and the undefined variable name from the faultstring element of the error response. For example, in the following faultstring, the PythonScript name is `myscript.py` and the undefined variable name is **num3**:\n\n ```python\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"NameError: 'num3' is not defined\"\"\n ```\n2. Examine the PythonScript source file identified in step #1 above and verify if the undefined variable identified in step #1 above is being referenced. For example, the following PythonScript code references the undefined variable **num3**, which matches the faultstring:\n\n ```python\n num1 = 1.5\n num2 = 6.3\n sum = float(num1) + float(num3)\n print('The sum of {0} and {1} is {2}'.format(num1, num3 sum))\n ```\n3. Check if the specific variable is defined within the PythonScript code. If the variable is not defined, then that's the cause for the error.\n\n In the example script shown above, the variable **num3** is undefined. Therefore, you will get the below error:\n\n \u003cbr /\u003e\n\n ```python\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"NameError: 'num3' is not defined\"\"\n ```\n\n \u003cbr /\u003e\n\nResolution\n\nEnsure that all the variables referenced in the PythonScript code are properly defined.\n\nTo fix the issue with the example PythonScript shown above, define the variable **num3** before using it. For example: \n\n```python\nnum1 = 1.5\nnum2 = 6.3\nnum3 = 8.7\nsum = float(num1) + float(num3)\nprint('The sum of {0} and {1} is {2}'.format(num1, num3, sum))\n```\n\nZeroDivisionError\n\nThis error is raised when the second argument of a division or modulo operation is zero.\n\nError response body \n\n```python\n{\n \"fault\": {\n \"faultstring\": \"Evaluation of script \u003cvar translate=\"no\"\u003epythonscript_name\u003c/var\u003e (py) failed with reason: \"ZeroDivisionError: reason_for_error\"\",\n \"detail\": {\n \"errorcode\": \"steps.script.ScriptEvaluationFailed\"\n }\n }\n}\n```\n\nExample error response body \n\n```python\n{\n \"fault\": {\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"ZeroDivisionError: integer division or modulo by zero\"\",\n \"detail\": {\n \"errorcode\": \"steps.script.ScriptEvaluationFailed\"\n }\n }\n}\n```\n\nDiagnosis\n\n1. Identify the PythonScript policy name and the reason for failure from the faultstring element of the error response. For example, in the following faultstring, the PythonScript name is `myscript.py` and the reason for failure is `integer division or modulo by zero`:\n\n ```python\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"ZeroDivisionError: integer division or modulo by zero\"\"\n ```\n2. Examine the PythonScript source file identified in step #1 above and verify if there's a division or a modulus operation by zero. For example, the following PythonScript code performs division by zero, which matches with what's in the faultstring:\n\n ```python\n a = 0\n b = 5\n c = b/a\n print c\n ```\n\n In the example script shown above, because the second argument of the division operation is zero, you get the following error: \n\n ```python\n \"faultstring\": \"Evaluation of script myscript.py (py) failed with reason: \"ZeroDivisionError: integer division or modulo by zero\"\"\n ```\n\nResolution\n\nEnsure that the second argument of a division or modulo operation is non zero in the PythonScript.\n\nTo fix the issue with the example PythonScript shown above, use a non zero value as the second argument of a division or modulo operation. For example: \n\n```python\na = 3\nb = 5\nc = b/a\nprint c\n```\n\nMore Information\n\nThere are many other possible causes for the error `steps.script.ScriptEvaluationFailed` apart from the ones described above. Please refer to the official [Python documentation](https://docs.python.org/3/library/exceptions.html) for more information."]]