kong attribute not found
abhisheksharma2805 opened this issue · 3 comments
I was trying to run one of the plugin examples but got the following error. I see that there is no kong module inside "kong_pdk.kong.kong". I think I am doing something wrong. Please help
Traceback (most recent call last):
File "auth_plugin.py", line 12, in
class Plugin(object):
File "auth_plugin.py", line 15, in Plugin
def access(self, kong: kong.kong):
AttributeError: module 'kong_pdk.pdk.kong' has no attribute 'kong'
Hi @abhisheksharma2805 , I think python interpreter doesn't like the type annotation though most IDE does.
For now you can remove the type annotation, there's no difference funcitonal wise:
def access(self, kong):
I will take a look on how to make type annotation work.
@fffonion For now this seems to work for me.
def access(self, kong):
host, err = kong.kong.request.get_header("host")
if err:
kong.kong.log.err(err)
message = "hello"
if 'message' in self.config:
message = self.config['message']
kong.kong.response.set_header("x-hello-from-python", "Python says %s to %s" % (message, host))
kong.kong.response.set_header("x-python-pid", str(os.getpid()))
@abhisheksharma2805 In the code you should still use the kong
class though, for example:
host, err = kong.request.get_header("host")
instead of
host, err = kong.kong.request.get_header("host")