I have a simple Flask Rest-Plus app that is serving as the micro-service front end for a Keen.io implementation. I've set up a custom virtual environment for the app and installed keen via pip install keen
. I can save events via the python console within that environment; however, when I try to do the same from a Flask endpoint, it throws the following error message:
[2017-08-03 12:31:02,784] ERROR in app: Exception on/api/analytics/track/pageview [POST]
Traceback (most recent call last):
File "/home/garrett/env/event-api/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/garrett/env/event-api/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/garrett/env/event-api/local/lib/python2.7/site-packages/flask_restplus/api.py", line 313, in wrapper
resp = resource(*args, **kwargs)
File "/home/garrett/env/event-api/local/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/home/garrett/env/event-api/local/lib/python2.7/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/garrett/dev/swiftshopper/event-api/api/analytics/endpoints/track.py", line 29, in post
track_event("pageview", payload)
File "/home/garrett/dev/swiftshopper/event-api/api/analytics/utils/keen.py", line 10, in track_event
keen.add_event("signups", {
AttributeError: 'module' object has no attribute 'add_event'
The code for calling it:
import keen
# This is your actual Project ID and Write Key
keen.project_id = "..."
keen.write_key = "..."
# Wrapper around event API
def track_event(event_name, payload):
#keen.add_event(event_name, payload)
keen.add_event("signups", {
"username": "lloyd",
"referred_by": "harry"
})
Appreciate support / ideas!