Kong/kong-python-pdk

'py-hello' cannot configured as a custom plugin

luqiang2013 opened this issue · 0 comments

kong.conf

pluginserver_py-hello_socket = /usr/local/kong/py-hello.socket
pluginserver_py-hello_start_cmd = /etc/kong/plugins/py-hello.py --no-lua-style
pluginserver_py-hello_query_cmd = /etc/kong/plugins/py-hello.py -dump

i configure it above, but when i run with cmd

kong start -c kong.conf

i got an error

Error: 
/usr/local/share/lua/5.1/kong/cmd/start.lua:211: /usr/local/share/lua/5.1/kong/cmd/start.lua:199: nginx: [warn] [kong] init.lua:388 the Granular tracing is deprecated, please use OpenTelemetry tracing to track the lifecycle of Kong instead. (deprecated after 3.0.0.0, scheduled for removal in 4.0.0.0)
nginx: [warn] [kong] [C]:-1 [Penlight 1.13.1] the contents of module 'pl.xml' has been deprecated, please use a more specialized library instead (deprecated after 1.11.0, scheduled for removal in 2.0.0)
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:629: error loading plugin schemas: on plugin 'py-hello': Plugin "py-hello" cannot be loaded because its VERSION field does not follow the "x.y.z" format, got: "nil".

here is the py-hello.py

#!/usr/bin/env python3
import os
import kong_pdk.pdk.kong as kong

Schema = (
    {"message": {"type": "string"}},
)

version = '0.1.0'
priority = 0


# This is an example plugin that add a header to the response

class Plugin(object):
    def __init__(self, config):
        self.config = config

    def access(self, kong: kong.kong):
        try:
            host, err = kong.request.get_header("host")
        except Exception as ex:
            pass  # error handling
        message = "hello"
        if 'message' in self.config:
            message = self.config['message']
        kong.response.set_header("x-hello-from-python", "Python says %s to %s" % (message, host))
        kong.response.set_header("x-python-pid", str(os.getpid()))


# add below section to allow this plugin optionally be running in a dedicated process
if __name__ == "__main__":
    from kong_pdk.cli import start_dedicated_server

    start_dedicated_server("py-hello", Plugin, version, priority, Schema)