{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: error_type: error_description"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "NameError:variable_nameisnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
錯誤回應主體範例
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
num1=1.5num2=6.3sum=float(num1)+float(num3)print('The sum of {0} and {1} is {2}'.format(num1,num3sum))
檢查 PythonScript 程式碼中是否定義了特定變數。如果未定義變數,則會導致錯誤。
在上方範例指令碼中,變數 num3 未定義。因此,您會收到以下錯誤訊息:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
解決方法
請確認 PythonScript 程式碼中參照的所有變數都已正確定義。
如要修正上述 PythonScript 範例的問題,請先定義變數 num3,再使用該變數。例如:
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
當除法或模運算的第二個引數為零時,系統會擲回此錯誤。
錯誤回應主體
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "ZeroDivisionError:reason_for_error"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
錯誤回應主體範例
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
診斷
從錯誤回應的錯誤字串元素中,找出 PythonScript 政策名稱和失敗原因。例如,在以下錯誤字串中,PythonScript 名稱為 myscript.py,失敗原因為 integer division or modulo by zero:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[[["\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."]]