Risoluzione dei problemi relativi agli errori di runtime dei criteri PythonScript
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Stai visualizzando la documentazione di Apigee e Apigee hybrid.
Visualizza la documentazione di
Apigee Edge.
ScriptEvaluationFailed
Codice di errore
steps.script.ScriptEvaluationFailed
Corpo della risposta di errore
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: error_type: error_description"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Cause possibili
Il criterio Script Python può generare diversi tipi di errori ScriptEvaluationFailed. Le sezioni seguenti descrivono alcuni di questi errori.
NameError
Se nel codice PythonScript è presente una variabile a cui viene fatto riferimento o su cui viene eseguito un'operazione senza essere definita, viene visualizzato l'errore Name.
Corpo della risposta di errore
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "NameError:variable_nameisnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Esempio di testo della risposta di errore
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnosi
Identifica il criterio PythonScript e il nome della variabile non definita dall'elemento faultstring della risposta di errore. Ad esempio, nel seguente faultstring, il nome di PythonScript è myscript.py e il nome della variabile non definita è num3:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Esamina il file di origine PythonScript identificato nel passaggio 1 sopra e verifica se viene fatto riferimento alla variabile non definita identificata nel passaggio 1 sopra. Ad esempio, il seguente codice PythonScript fa riferimento alla variabile non definita num3, che corrisponde a faultstring:
num1=1.5num2=6.3sum=float(num1)+float(num3)print('The sum of {0} and {1} is {2}'.format(num1,num3sum))
Controlla se la variabile specifica è definita all'interno del codice PythonScript. Se la variabile non è definita, è la causa dell'errore.
Nello script di esempio riportato sopra, la variabile num3 non è definita. Di conseguenza, verrà visualizzato il seguente errore:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Risoluzione
Assicurati che tutte le variabili a cui viene fatto riferimento nel codice PythonScript siano definite correttamente.
Per risolvere il problema con l'esempio PythonScript mostrato sopra, definisci la variabile num3 prima di utilizzarla. Ad esempio:
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
Questo errore viene generato quando il secondo argomento di un'operazione di divisione o modulo è zero.
Corpo della risposta di errore
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "ZeroDivisionError:reason_for_error"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Esempio di testo della risposta di errore
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnosi
Identifica il nome del criterio PythonScript e il motivo dell'errore dall'elemento faultstring della risposta di errore. Ad esempio, nella stringa di errore seguente, il nome di PythonScript è myscript.py e il motivo dell'errore è integer division or modulo by zero:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Esamina il file di origine PythonScript identificato nel passaggio 1 sopra e verifica se è presente un'operazione di divisione o modulo per zero. Ad esempio, il seguente codice PythonScript esegue la divisione per zero, che corrisponde a quanto indicato in faultstring:
a=0b=5c=b/aprintc
Nello script di esempio mostrato sopra, poiché il secondo argomento dell'operazione di divisione è zero, viene visualizzato il seguente errore:
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Risoluzione
Assicurati che il secondo argomento di un'operazione di divisione o modulo non sia pari a zero in PythonScript.
Per risolvere il problema con l'esempio PythonScript mostrato sopra, utilizza un valore diverso da zero come secondo argomento di un'operazione di divisione o modulo. Ad esempio:
a=3b=5c=b/aprintc
Ulteriori informazioni
Esistono molte altre cause possibili dell'errore steps.script.ScriptEvaluationFailed oltre a quelle descritte sopra. Per ulteriori informazioni, consulta la documentazione ufficiale di Python.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 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,["# PythonScript policy runtime error troubleshooting\n\n*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----------------------\n\n### Error code\n\n steps.script.ScriptEvaluationFailed\n\n### Error 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\n### Possible 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---------\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\n### Error 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\n### Example 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\n### Diagnosis\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\n### Resolution\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-----------------\n\nThis error is raised when the second argument of a division or modulo operation is zero.\n\n### Error 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\n### Example 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\n### Diagnosis\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\n### Resolution\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----------------\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."]]