आपको Apigee Edge दस्तावेज़ दिख रहा है.
अभी तक किसी भी व्यक्ति ने चेक इन नहीं किया है
इस पेज पर जाएं
Apigee X दस्तावेज़. जानकारी

क्या
Python स्क्रिप्ट नीति से आपको अपने एपीआई प्रॉक्सी फ़्लो में, पसंद के मुताबिक Python फ़ंक्शन जोड़ने की सुविधा मिलती है. खास तौर पर, ऐसा तब होता है, जब आपकी ज़रूरत के हिसाब से Edge की आउट-टू-डेट नीतियों से ज़्यादा सुविधाएं हों उपलब्ध कराएँ.
Jython के ज़रिए Python भाषा से जुड़ी सहायता दी जाती है वर्शन 2.5.2 है. जोड़ी जाने वाली तीसरे पक्ष की लाइब्रेरी "प्योर Python" होनी चाहिए (सिर्फ़ Python में लागू किया जाता है). लाइब्रेरी जोड़ने के बारे में ज़्यादा जानने के लिए, संसाधन फ़ाइलें देखें.
Python नीति में कोई असल कोड नहीं होता. इसके बजाय, Python नीति में Python का रेफ़रंस दिया जाता है
संसाधन और एपीआई फ़्लो में उस चरण को तय करता है जहां Python स्क्रिप्ट काम करती है. अपलोड करने के लिए
प्रबंधन यूज़र इंटरफ़ेस (यूआई) प्रॉक्सी एडिटर के ज़रिए अपनी स्क्रिप्ट भेज सकते हैं या आप उसे
एपीआई प्रॉक्सी में /resources/py
डायरेक्ट्री, जिसे आपने स्थानीय तौर पर डेवलप किया है.
सैंपल
Python नीति और स्क्रिप्ट
Python स्क्रिप्ट से जुड़ी नीति
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Script name="Python-1"> <DisplayName>Python-1</DisplayName> <ResourceURL>py://myscript.py</ResourceURL> </Script>
इस उदाहरण में, ResourceURL, काम की Python स्क्रिप्ट के बारे में बताता है संसाधन.
Python स्क्रिप्ट
यह दिखाता है कि Python स्क्रिप्ट में क्या शामिल किया जा सकता है.
import base64 username = flow.getVariable("request.formparam.client_id") password = flow.getVariable("request.formparam.client_secret") base64string = base64.encodestring('%s:%s' % (username, password))[:-1] authorization = "Basic "+base64string flow.setVariable("authorizationParam",authorization)
एलिमेंट का रेफ़रंस
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Script name="Python-1"> <DisplayName>Python-1</DisplayName> <ResourceURL>py://myscript.py</ResourceURL> <IncludeURL>py://myscript_dependency.py</IncludeURL> </Script>
यहां दी गई टेबल में, ऐसे एट्रिब्यूट के बारे में बताया गया है जो नीति के सभी पैरंट एलिमेंट में एक जैसे होते हैं:
एट्रिब्यूट | ब्यौरा | डिफ़ॉल्ट | मौजूदगी |
---|---|---|---|
name |
नीति का अंदरूनी नाम. इसके अलावा, नीति को लेबल करने के लिए, |
लागू नहीं | ज़रूरी है |
continueOnError |
किसी नीति के काम न करने पर, गड़बड़ी दिखाने के लिए नीति के लागू होने के बाद भी फ़्लो को एक्ज़ीक्यूट करने के लिए, इसे |
गलत | वैकल्पिक |
enabled |
नीति को लागू करने के लिए, नीति को बंद करने के लिए, |
सही | वैकल्पिक |
async |
यह एट्रिब्यूट अब काम नहीं करता. |
गलत | बहिष्कृत |
<DisplayName> एलिमेंट
इस कॉलम में नीति को लेबल करने के लिए, name
एट्रिब्यूट के साथ-साथ इस्तेमाल करें
मैनेजमेंट यूज़र इंटरफ़ेस (यूआई) प्रॉक्सी एडिटर, जिसका नाम अलग और सामान्य भाषा में है.
<DisplayName>Policy Display Name</DisplayName>
डिफ़ॉल्ट |
लागू नहीं अगर आप इस एलिमेंट को छोड़ देते हैं, तो नीति की |
---|---|
मौजूदगी | वैकल्पिक |
टाइप | स्ट्रिंग |
<ResourceURL> एलिमेंट
यह एलिमेंट मुख्य Python फ़ाइल के बारे में बताता है, जो एपीआई फ़्लो में काम करेगी. आपके पास यह स्टोर करने का विकल्प है
यह फ़ाइल एपीआई प्रॉक्सी दायरे में (एपीआई प्रॉक्सी में /apiproxy/resources/py
के तहत)
बंडल या एपीआई प्रॉक्सी एडिटर के नेविगेटर पैनल के स्क्रिप्ट सेक्शन में) या
एक से ज़्यादा एपीआई प्रॉक्सी में फिर से इस्तेमाल करने के लिए, संगठन या एनवायरमेंट के दायरे
संसाधन फ़ाइलें. आपका कोड,
JavaScript ऑब्जेक्ट मॉडल के ऑब्जेक्ट, तरीके, और प्रॉपर्टी.
<ResourceURL>py://myscript.py</ResourceURL>
डिफ़ॉल्ट: | कोई नहीं |
मौजूदगी: | ज़रूरी है |
टाइप: | स्ट्रिंग |
<IncludeURL> एलिमेंट
इस नीति से, मुख्य Python फ़ाइल के लिए डिपेंडेंसी के तौर पर लोड की जाने वाली Python फ़ाइल के बारे में बताता है
<ResourceURL>
एलिमेंट. स्क्रिप्ट का आकलन इसी क्रम में किया जाएगा
वे नीति में शामिल हैं.
अतिरिक्त के साथ एक से ज़्यादा Python डिपेंडेंसी संसाधन शामिल करें
<IncludeURL>
एलिमेंट.
<IncludeURL>py://myscript_dependency.py</IncludeURL>
डिफ़ॉल्ट: | कोई नहीं |
मौजूदगी: | वैकल्पिक |
टाइप: | स्ट्रिंग |
गड़बड़ी कोड
This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Runtime errors
These errors can occur when the policy executes.
Fault code | HTTP status | Cause | Fix |
---|---|---|---|
steps.script.ScriptEvaluationFailed |
500 | The PythonScript policy can throw several different types of ScriptExecutionFailed errors. Commonly seen types of errors include NameError and ZeroDivisionError. | build |
Deployment errors
These errors can occur when you deploy a proxy containing this policy.
Error name | Cause | Fix |
---|---|---|
InvalidResourceUrlFormat |
If the format of the resource URL specified within the <ResourceURL> or
the <IncludeURL> element of the PythonScript policy is invalid, then the deployment of the API proxy fails. |
build |
InvalidResourceUrlReference |
If the <ResourceURL> or the <IncludeURL> elements
refer to a PythonScript file that does not exist, then the deployment of the API proxy fails.
The referenced source file must exist either the API proxy, environment, or organization level. |
build |
Fault variables
These variables are set when this policy triggers an error at runtime. For more information, see What you need to know about policy errors.
Variables | Where | Example |
---|---|---|
fault.name="fault_name" |
fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. | fault.name Matches "ScriptExecutionFailed" |
pythonscript.policy_name.failed |
policy_name is the user-specified name of the policy that threw the fault. | pythonscript.PythonScript-1.failed = true |
Example error response
{ "fault": { "faultstring": "Execution of SetResponse failed with error: Pythonscript runtime error: "ReferenceError: "status" is not defined.\"", "detail": { "errorcode": "steps.script.ScriptExecutionFailed" } } }
Example fault rule
<FaultRule name="PythonScript Policy Faults"> <Step> <Name>AM-CustomErrorResponse</Name> <Condition>(fault.name Matches "ScriptExecutionFailed") </Condition> </Step> <Condition>(pythonscript.PythonScript-1.failed = true) </Condition> </FaultRule>