PythonScript policy deployment error troubleshooting

InvalidResourceUrlFormat

Error message

Deployment of an API proxy through either the Edge UI or Edge management API fails with this error message:

Error Deploying Revision revision_number to environment
Invalid resource url format. Resource url is invalid_URL.

Example error message

Error Deploying Revision 2 to prod
Invalid resource url format. Resource url is py:myscript.py.

Example screenshot

Cause

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.

The correct format is as shown below:

<ResourceURL>py://file_name.py</ResourceURL>
<IncludeURL>py://file_name.py</IncludeURL>

For example, if the <ResourceURL> element is specified as shown below, then the deployment of the API proxy fails because it does not follow the required pattern:

<ResourceURL>py:myscript.py</ResourceURL>

Diagnosis

  1. Identify the invalid resource URL format used in the PythonScript policy. You can find this information from the error message. For example, in the following error, the invalid resource URL format is py:myscript.py:

    Invalid resource url format. Resource url is py:myscript.py.
    
  2. Examine all the PythonScript policies in the specific API Proxy where the failure has occurred. If there is any PythonScript policy in which the resource URL specified in the <ResourceURL> or the <IncludeURL> element matches the invalid entry identified in step #1 above, then that's the cause of the error.

    For example, the following policy specifies the resource URL as py:myscript.py, which matches what's in the error message:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Script async="false" continueOnError="false" enabled="true" timeLimit="200" name="py-TotalVariable">
        <DisplayName>py-TotalVariable</DisplayName>
        <Properties/>
        <ResourceURL>py:myscript.py</ResourceURL>
    </Script>
    

    Since the resource URL is specified as py:myscript.py, which is invalid, the deployment of the API Proxy fails with the error:

    Invalid resource url format. Resource url is py:myscript.py.
    

Resolution

Ensure that the resource URL format specified in the <ResourceURL> element of the PythonScript policy is valid. For example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Script async="false" continueOnError="false" enabled="true" timeLimit="200" name="py-TotalVariable">
    <DisplayName>py-TotalVariable</DisplayName>
    <Properties/>
    <ResourceURL>py://myscript.py</ResourceURL>
</Script>

InvalidResourceUrlReference

Error message

Deployment of an API proxy through either the Edge UI or Edge management API fails with this error message:

Error Deploying Revision revision_number to environment
Invalid resource url ref invalid_reference in policy policy_name in org_name

Example error message

Error Deploying Revision 2 to prod
Invalid resource url ref py://myscript.py in policy Python_script in myorg

Example screenshot

Cause

If the <ResourceURL> and <IncludeURL> elements refer to a PythonScript file that does not exist, then the deployment of the API proxy fails. If you are deploying a proxy bundle from your local machine, then the PythonScript source files must be stored under /apiproxy/resources/py(at the API proxy scope).

In the Edge UI, the PythonScript source files appear under py in the Scripts section of the API proxy editor's Navigator pane as shown below:

You can also store resource files in organization and environment level repositories (to make PythonScript code available to all proxies in an org or env, for example). If any resource files specified in the policy cannot be found, then this error occurs.

Diagnosis

  1. Identify the PythonScript policy where the error occurred and the invalid resource URL reference. You can find this information from the error message. For example, in the following error, the policy name is Python_script and the invalid resource URL reference is py://myscript.py:

    Invalid resource url ref py://myscript.py in policy Python_script in myorg
    
  2. Verify that the resource URL reference specified in the failed PythonScript policy matches with the value identified in the error message (step #1 above). For example, the following policy specifies the resource URL reference as py://myscript.py, which matches what's in the error message:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Script async="false" continueOnError="false" enabled="true" name="Python_script">
        <DisplayName>Python-1</DisplayName>
        <Properties/>
        <ResourceURL>py://myscript.py</ResourceURL>
    </Script>
    
  3. Check if the file identified in step #1 file is part of the specific API Proxy bundle, or exists at the organization or environment scope.

    1. To check if the file is part of the specific API Proxy bundle, follow one of the below steps:
      1. In the Edge UI, check if this file is in the Scripts section of the API proxy.
      2. Download the API Proxy bundle and search if the file exists.
    2. If the file is not part of the specific API Proxy bundle, then check if it exists at the organization or environment level. You can use the Resource Files API for this investigation.

    If the file does not exist at the API Proxy, organization, or environment level, then that's the cause of the error.

    In the example above, the invalid PythonScript filename is myscript.py. In the screenshot below, notice that the file specified as a resource URL in the policy does not appear in the Scripts section. Also the file does not exist at the organization or environment level. Therefore, the deployment of the API Proxy fails with the error:

    Invalid resource url ref py://myscript.py in policy Python_script in myorg
    

Resolution

Ensure that the PythonScript files specified in <ResourceURL> and <IncludeURL> elements refer to a valid file that exists at the API Proxy, organization, or environment level.

To correct the example PythonScript policy shown above, add the file myscript.py to the API Proxy bundle. In the screenshot below you can see that the PythonScript files specified in <ResourceURL> and <IncludeURL> elements are visible in the Scripts section of the API Proxy bundle: