Can't initiate dispatcher

Hi,

Sorry it’s me again :sweat_smile:

I tried to install Tyk on my new computer. The point was to know how much time is required for a fresh install now that I did it once already and to keep working on the new computer.

Everything went pretty well until trying to work on python plugin again.
Below is that trace of the service tyk-gateway-python.

From the problem seems to be from “ImportError: No module named ‘dispatcher’”. But the PYTHONPATH seems ok to me… I don’t know what I can do to fix it.
Here is the ls of /opt/tyk-gateway/coprocess/python :
binding.h cythonize dispatcher.h dispatcher.py init.py proto README.md tyk

Other details :
Python3.4 is installed
libpython3.4 is also installed
I followed the whole procedure from //tyk.io/docs/plugins/supported-languages/rich-plugins/python/python/

Any input on how to fix this ?

Thanks !

$ sudo /opt/tyk-gateway/tyk-python --conf=/opt/tyk-gateway/tyk.conf
[Oct 25 16:26:18] INFO Connection dropped, connecting…
[Oct 25 16:26:18] INFO python: Setting PYTHONPATH to ‘coprocess/python:middleware/python:event_handlers:coprocess/python/proto:/opt/tyk-gateway/middleware/bundles/6cf95519e7e348cb44d26c73ee596b34-bundle20.zip’
[Oct 25 16:26:18] INFO python: Initializing interpreter, Py_Initialize()
ImportError: No module named ‘dispatcher’
[Oct 25 16:26:18] ERROR coprocess: Can’t initialize a dispatcher
[Oct 25 16:26:18] INFO main: Setting up analytics normaliser
[Oct 25 16:26:18] INFO main: PIDFile location set to: ./tyk-gateway.pid
[Oct 25 16:26:18] ERROR Instrumentation is enabled, but no connectionstring set for statsd
[Oct 25 16:26:18] INFO main: Initialising Tyk REST API Endpoints
[Oct 25 16:26:18] INFO main: → Standard listener (http)
[Oct 25 16:26:18] INFO main: Setting up Server
[Oct 25 16:26:18] INFO main: Waiting for zeroconf signal…
[Oct 25 16:26:18] WARN pub-sub: Insecure configuration detected (allowing)!
[Oct 25 16:26:18] INFO pub-sub: Hostname set with dashboard zeroconf signal
[Oct 25 16:26:19] INFO main: Registering node.
[Oct 25 16:26:19] INFO dashboard: Node registered id=aa7b167b-e468-47e0-5ab2-dd61aa76d1be
[Oct 25 16:26:19] INFO main: Initialising distributed rate limiter
[Oct 25 16:26:19] INFO Starting gateway rate imiter notifications…
[Oct 25 16:26:19] INFO main: Detected 2 APIs
[Oct 25 16:26:19] INFO main: Loading API configurations.
[Oct 25 16:26:19] INFO main: Tracking hostname api_name=directus local domain=(no host)
[Oct 25 16:26:19] INFO main: Tracking hostname api_name=httpbin domain=(no host)
[Oct 25 16:26:19] INFO main: Loading API api_name=directus local
[Oct 25 16:26:19] INFO main: Loading existing bundle: bundle20.zip
[Oct 25 16:26:19] INFO main: ----> Loading bundle: bundle20.zip
[Oct 25 16:26:19] INFO main: ----> Using bundle: bundle20.zip
[Oct 25 16:26:19] INFO main: Checking security policy: Token api_name=directus local
[Oct 25 16:26:19] INFO gateway: Loaded: directus local api_id=6cf95519e7e348cb44d26c73ee596b34 org_id=59f04bebe1c0713f685642b9 server_name=-- user_id=-- user_ip=–
[Oct 25 16:26:19] INFO main: Loading API api_name=httpbin
[Oct 25 16:26:19] INFO main: Checking security policy: Token api_name=httpbin
[Oct 25 16:26:19] INFO gateway: Loaded: httpbin api_id=a4ca5972661a47a3588e0cb072645a6d org_id=59f04bebe1c0713f685642b9 server_name=-- user_id=-- user_ip=–
[Oct 25 16:26:20] INFO main: Processed and listening on: /directus-local/{rest:.}
[Oct 25 16:26:20] INFO main: Processed and listening on: /httpbin/{rest:.
}
[Oct 25 16:26:20] INFO host-check-mgr: Loading uptime tests…
[Oct 25 16:26:20] INFO main: Initialised API Definitions
[Oct 25 16:26:20] INFO main: Loading policies
[Oct 25 16:26:20] INFO main: Using Policies from Dashboard Service
[Oct 25 16:26:20] INFO policy: Mutex lock acquired… calling
[Oct 25 16:26:20] INFO policy: Calling dashboard service for policy list
[Oct 25 16:26:20] INFO policy: Processing policy list
[Oct 25 16:26:20] INFO policy: → Processing policy ID: 59f05129e1c0713f685642bb
[Oct 25 16:26:20] INFO main: Gateway started (v2.3.11)
[Oct 25 16:26:20] INFO main: → Listening on address: (open interface)
[Oct 25 16:26:20] INFO main: → Listening on port: 8080
[Oct 25 16:26:20] INFO main: → PID: 2874
[Oct 25 16:26:22] INFO pub-sub: Using /opt/tyk-gateway/tyk.conf for configuration

Follow up:

I tried to work with JS in the meantime, I now get the following error : “Failed to run JS middleware: TypeError: Cannot access member ‘DoProcessRequest’ of undefined”.

“enable_jsvm” is enabled.
The middleware file is the one from the tutorial https://tyk.io/docs/customise-tyk/plugins/javascript-middleware/middleware-scripting-guide/

I’m very lost, never had much issue with the JS middleware. What am I missing ?

As usual, logs from the service:
systemd[1]: Started Tyk API Gateway.
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“Connection dropped, connecting…”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“Setting up analytics normaliser”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“PIDFile location set to: ./tyk-gateway.pid”
tyk[8645]: time=“Oct 25 18:27:45” level=error msg=“Instrumentation is enabled, but no connectionstring set for statsd”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“Initialising Tyk REST API Endpoints”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“–> Standard listener (http)”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“Setting up Server”
tyk[8645]: time=“Oct 25 18:27:45” level=info msg=“Waiting for zeroconf signal…”
tyk[8645]: time=“Oct 25 18:27:47” level=warning msg=“Insecure configuration detected (allowing)!”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Hostname set with dashboard zeroconf signal”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Registering node.”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Node registered” id=aa7b167b-e468-47e0-5ab2-dd61aa76d1be
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Initialising distributed rate limiter”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Starting gateway rate imiter notifications…”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Detected 2 APIs”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loading API configurations.”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Tracking hostname” api_name=“directus local” domain=“(no host)”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Tracking hostname” api_name=httpbin domain=“(no host)”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loading API” api_name=“directus local”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loading API” api_name=httpbin
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Checking security policy: Token” api_name=httpbin
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loaded: httpbin” api_id=a4ca5972661a47a3588e0cb072645a6d org_id=59f04bebe1c0713f685642b9 server_name=-- user_id=-- user_ip=–
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loading JS File: /opt/tyk-gateway/middleware/6cf95519e7e348cb44d26c73ee596b34/post/sampleMiddleware.js”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Checking security policy: Token” api_name=“directus local”
tyk[8645]: time=“Oct 25 18:27:47” level=info msg=“Loaded: directus local” api_id=6cf95519e7e348cb44d26c73ee596b34 org_id=59f04bebe1c0713f685642b9 server_name=-- user_id=-- user_ip=–
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Processed and listening on: /directus-local/{rest:.}"
tyk[8645]: time=“Oct 25 18:27:48” level=info msg="Processed and listening on: /httpbin/{rest:.
}”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Loading uptime tests…”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Initialised API Definitions”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Loading policies”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Using Policies from Dashboard Service”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Mutex lock acquired… calling”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Calling dashboard service for policy list”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Processing policy list”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“–> Processing policy ID: 59f05129e1c0713f685642bb”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“Gateway started (v2.3.11)”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“–> Listening on address: (open interface)”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“–> Listening on port: 8080”
tyk[8645]: time=“Oct 25 18:27:48” level=info msg=“–> PID: 8645”
tyk[8645]: time=“Oct 25 18:27:48” level=error msg=“Failed to run JS middleware: TypeError: Cannot access member ‘DoProcessRequest’ of undefined”
tyk[8645]: time=“Oct 25 18:27:50” level=info msg=“Using /opt/tyk-gateway/tyk.conf for configuration”

Sorry for multiple posts but I keep trying to find solutions and finding more and more weird stuff.

I checked out the project from Github to check where the errors are coming from.
For the JS issue I noticed that the /opt/tyk-gateway/js/tyk.js was missing from my install, the content of the templates folder too.
Adding the tyk.js file from the master repo changed the error to “Failed to run JS middleware: ReferenceError: ‘b64dec’ is not defined”.
I copied the templates files too.

But basically my install seems messed up with multiple missing files (as far as I understand). So I tried reinstalling but no success, I still have the same issue. I noticed the version update and tried installing older version, still the same.

I really have no idea what the hell is going on there. Any input on this would be amazing !
I will try to install on a brand new VM to check if it works better.

Details:
Ubuntu 16.04, fresh installation
Tyk-gateway 2.3.11
Followed the documentation for installation

Thanks,
Robert

Hello again :slight_smile:

So I reinstalled tyk-gateway and redis again but this time after calling apt-get remove, I also called apt-get purge and rm -rf /opt/tyk-gateway/.

Now I get the templates and JS files when installing tyk-gateway. Don’t know what happened but it seems okay now.

My JS middleware now works too.

It leaves us with Pyhton. When I started back I still had the error “No module named ‘dispatcher’” but I added "python_path_prefix": "/opt/tyk-gateway/" to my tyk.conf and now the error changed. Here is the stack trace :
[Oct 26 19:17:16] INFO python: Setting PYTHONPATH to '/opt/tyk-gateway/coprocess/python:/opt/tyk-gateway/middleware/python:/opt/tyk-gateway/event_handlers:/opt/tyk-gateway/coprocess/python/proto' [Oct 26 19:17:16] INFO python: Initializing interpreter, Py_Initialize() Traceback (most recent call last): File "/opt/tyk-gateway/coprocess/python/dispatcher.py", line 7, in <module> from tyk.object import TykCoProcessObject File "/opt/tyk-gateway/coprocess/python/tyk/object.py", line 3, in <module> from tyk.session import TykSession File "/opt/tyk-gateway/coprocess/python/tyk/session.py", line 1, in <module> import coprocess_session_state_pb2 as session_state_pb File "/opt/tyk-gateway/coprocess/python/proto/coprocess_session_state_pb2.py", line 6, in <module> from google.protobuf import descriptor as _descriptor ImportError: No module named 'google' [Oct 26 19:17:16] ERROR coprocess: Can't initialize a dispatcher

From the file /opt/tyk-gateway/coprocess/python/proto/coprocess_session_state_pb2.py it looks like an issue with protobuf. I tried uninstalling it and restarting the process to build it from //tyk.io/docs/plugins/supported-languages/rich-plugins/python/python/ but I still get the issue.

Any idea of what’s going on ? During the building & install it told me that protobuf was installed in Installed /usr/local/lib/python3.5/dist-packages/protobuf-3.1.0-py3.5-linux-x86_64.egg. Could it be because Tyk uses Python3.4 ?

Thanks !

You need to use Python 3.4
And you need to install all the dependencies under 3.4 :slight_smile:

Okay thanks for feedback :slight_smile:

I will try to see how to setup the dependencies in 3.4 but we will probably work with gRPC servers in the end :wink: