Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make run: KeyError: 'token' error #33

Closed
mrplow opened this issue Feb 24, 2015 · 6 comments
Closed

make run: KeyError: 'token' error #33

mrplow opened this issue Feb 24, 2015 · 6 comments
Labels

Comments

@mrplow
Copy link

mrplow commented Feb 24, 2015

Sorry if this is on my end but I'm not sure why this is failing.
The make run command is failing with a KeyError: 'token' error. My ~/.bashrc file has the export line setup correctly I believe. That being said, after running make install limbo runs just fine ;)

Adding beautifulsoup4 4.3.2 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for importlib==1.0.3
Best match: importlib 1.0.3
Adding importlib 1.0.3 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for websocket-client==0.22.0
Best match: websocket-client 0.22.0
Adding websocket-client 0.22.0 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for requests==2.5.2
Best match: requests 2.5.2
Processing requests-2.5.2-py2.7.egg
requests 2.5.2 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/requests-2.5.2-py2.7.egg
Searching for backports.ssl-match-hostname==3.4.0.2
Best match: backports.ssl-match-hostname 3.4.0.2
Adding backports.ssl-match-hostname 3.4.0.2 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for six==1.8.0
Best match: six 1.8.0
Adding six 1.8.0 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Finished processing dependencies for limbo==3.0.0a2
make clean
make[1]: Entering directory `/home/ubuntu/slask'
rm -rf build dist limbo.egg-info
make[1]: Leaving directory `/home/ubuntu/slask'
bin/limbo
Traceback (most recent call last):
  File "bin/limbo", line 17, in <module>
    main(args)
  File "/usr/local/lib/python2.7/dist-packages/limbo-3.0.0a2-py2.7.egg/limbo/limbo.py", line 165, in main
    server = init_server(args)
  File "/usr/local/lib/python2.7/dist-packages/limbo-3.0.0a2-py2.7.egg/limbo/limbo.py", line 154, in init_server
    slack = Client(config["token"])
KeyError: 'token'
make: *** [run] Error 1
ubuntu@ip-172-31-28-218:~/slask$ echo $SLACK_TOKEN
xoxb-REDACTED28-REDACTEDREDACTEDREDACTEDT
@llimllib
Copy link
Owner

Thanks for reporting, and sorry you're hitting a bug.

The usual cause of this problem is that you've set the environment variable but not exported it. For example:

$ SLACK_TOKEN=<my_token>

$ bin/limbo
2015-02-24 09:39:46,979:DEBUG:config: {'loglevel': 'DEBUG'}
<... logging omitted ...>
Traceback (most recent call last):
  File "bin/limbo", line 17, in <module>
    main(args)
  File "/Users/llimllib/.virtualenvs/limbo/lib/python2.7/site-packages/limbo-3.0.0a1-py2.7.egg/limbo/limbo.py", line 165, in main
    server = init_server(args)
  File "/Users/llimllib/.virtualenvs/limbo/lib/python2.7/site-packages/limbo-3.0.0a1-py2.7.egg/limbo/limbo.py", line 154, in init_server
    slack = Client(config["token"])
KeyError: 'token'

But after;

$ export SLACK_TOKEN=<my_token>

bin/limbo works correctly. Are you certain that the variable is being exported? Can you paste the log output of bin/limbo, which should show the configuration it finds?

@llimllib
Copy link
Owner

I added an error message to the code that prints a more informative error in this case.

@mrplow
Copy link
Author

mrplow commented Feb 24, 2015

Its strange, I only get the error while running sudo make run
Python isn't seeing any env variables while run as sudo?
The env variable is saved in ~/.bashrc and the machine has been rebooted even.
Running
export SLACK_TOKEN=MYREALAPITOKEN
before sudo make run doesn't help either.

Using /usr/local/lib/python2.7/dist-packages
Searching for six==1.8.0
Best match: six 1.8.0
Adding six 1.8.0 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Finished processing dependencies for limbo==3.0.0a2
make clean
make[1]: Entering directory `/home/ubuntu/slask'
rm -rf build dist limbo.egg-info
make[1]: Leaving directory `/home/ubuntu/slask'
bin/limbo
2015-02-24 17:10:39,394:ERROR:Unable to find a slack token. The environment variables
limbo sees are:
{}

and the current config is:
{}

Try setting your bot's slack token with:

export SLACK_TOKEN=<your-slack-bot-token>

Traceback (most recent call last):
  File "bin/limbo", line 17, in <module>
    main(args)
  File "/usr/local/lib/python2.7/dist-packages/limbo-3.0.0a2-py2.7.egg/limbo/limbo.py", line 184, in main
    server = init_server(args)
  File "/usr/local/lib/python2.7/dist-packages/limbo-3.0.0a2-py2.7.egg/limbo/limbo.py", line 160, in init_server
    slack = Client(config["token"])
KeyError: 'token'
make: *** [run] Error 1

If I run bin/slasklimbo it runs fine and I have no errors

@llimllib
Copy link
Owner

When you run sudo, you're actually starting another shell as root, which means that it comes with a whole new set of environment variables, which doesn't include the ones in your user environment. That's why limbo can't find them.

I recommend that you either avoid running limbo as root or figure out how to set the environment variables such that the process will have access to them.

For example, I use an upstart script to start my instance of limbo, it looks like:

start on net-device-up
respawn
respawn limit 3 30

env SLACK_TOKEN=xoxb-<rest of token>
env LIMBO_LOGLEVEL=INFO
env LIMBO_LOGFILE=/var/log/limbo

exec /srv/limbo/bin/limbo

@llimllib
Copy link
Owner

Marking as closed, but feel free to keep asking for help, and thanks again for reporting!

@mrplow
Copy link
Author

mrplow commented Feb 24, 2015

Thanks, I'll steal use your upstart script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants