Résoudre les erreurs d'exécution de la règle PythonScript
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous consultez la documentation d'Apigee et d'Apigee hybrid. Consultez la documentation d'Apigee Edge.
ScriptEvaluationFailed
Code d'erreur
steps.script.ScriptEvaluationFailed
Corps de la réponse d'erreur
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: error_type: error_description"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Causes possibles
La règle PythonScript peut signaler plusieurs types d'erreurs ScriptEvaluationFailed. Les sections ci-dessous décrivent certaines de ces erreurs.
NameError
S'il existe une variable dans le code PythonScript qui est référencée ou utilisée sans avoir été définie, l'erreur NameError s'affiche.
Corps de la réponse d'erreur
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "NameError:variable_nameisnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Exemple de corps de réponse d'erreur
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnostic
Identifiez la règle PythonScript et le nom de la variable non définie à partir de l'élément faultstring de la réponse d'erreur. Par exemple, dans l'élément faultstring suivant, le nom PythonScript est myscript.py et le nom de la variable non définie est num3 :
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Examinez le fichier source PythonScript identifié à l'étape 1 ci-dessus et vérifiez si la variable non définie identifiée à l'étape 1 ci-dessus est référencée. Par exemple, le code PythonScript suivant référence la variable num3 non définie, qui correspond à l'élément faultstring :
num1=1.5num2=6.3sum=float(num1)+float(num3)print('The sum of {0} and {1} is {2}'.format(num1,num3sum))
Vérifiez si la variable spécifique est définie dans le code PythonScript. Si la variable n'est pas définie, il s'agit de la cause de l'erreur.
Dans l'exemple de script ci-dessus, la variable num3 n'est pas définie. Par conséquent, vous obtenez l'erreur suivante :
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "NameError:'num3'isnotdefined""
Solution
Vérifiez que toutes les variables référencées dans le code PythonScript sont correctement définies.
Pour résoudre le problème de l'exemple PythonScript présenté ci-dessus, définissez la variable num3 avant de l'utiliser. Exemple :
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
Cette erreur est générée lorsque le deuxième argument d'une opération modulo ou de division est égal à zéro.
Corps de la réponse d'erreur
{"fault":{"faultstring":"Evaluation of script pythonscript_name (py) failed with reason: "ZeroDivisionError:reason_for_error"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Exemple de corps de réponse d'erreur
{"fault":{"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero"","detail":{"errorcode":"steps.script.ScriptEvaluationFailed"}}}
Diagnostic
Identifiez le nom de la règle PythonScript et le motif de l'échec à partir de l'élément failstring de la réponse d'erreur. Par exemple, dans l'élément faultstring suivant, le nom PythonScript est myscript.py et le motif de l'échec est integer division or modulo by zero :
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Examinez le fichier source PythonScript identifié à l'étape01 ci-dessus et vérifiez s'il existe une opération modulo ou de division égale à zéro. Par exemple, le code PythonScript suivant effectue une division par zéro, qui correspond au contenu de l'élément faultstring :
a=0b=5c=b/aprintc
Dans l'exemple de script ci-dessus, le deuxième argument de l'opération de division étant égal à zéro, l'erreur suivante s'affiche :
"faultstring":"Evaluation of script myscript.py (py) failed with reason: "ZeroDivisionError:integerdivisionormodulobyzero""
Solution
Assurez-vous que le deuxième argument d'une opération modulo ou de division n'est pas nul dans PythonScript.
Pour résoudre le problème de l'exemple PythonScript présenté ci-dessus, utilisez une valeur différente de zéro comme deuxième argument d'une opération modulo ou de division. Exemple :
a=3b=5c=b/aprintc
En savoir plus
Il existe de nombreuses autres causes possibles de l'erreur steps.script.ScriptEvaluationFailed outre celles décrites ci-dessus. Pour en savoir plus, consultez la documentation officielle de Python.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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."]]