Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dictionary passed into machine class is not used on slack client

See original GitHub issue


Passing settings into the Machine class is ignored when generating the SlackClient. The Slack client class just runs a local_settings import via import_settings() when this seems to be unnecessary.

from machine import Machine
from machine.utils.collections import CaseInsensitiveDict

base_settings = {
    'PLUGINS': [],
    'DISABLE_HTTP': True,
    'HTTP_SERVER_PORT': 8080,
    'HTTP_SERVER_BACKEND': 'wsgiref',
    'HTTP_PROXY': None,
    'HTTPS_PROXY': None,
    'KEEP_ALIVE': None,
    'SLACK_API_TOKEN': '<redacted token>'

settings = CaseInsensitiveDict(base_settings)
bot = Machine(settings=settings)


pipenv run python                                     
Loading .env environment variables…
Initializing Slack Machine:
    Loading settings...
Traceback (most recent call last):
  File "", line 18, in <module>
    bot = Machine(settings=settings)
  File "/Users/henry.hollenstain/.virtualenvs/bot-9dQm3zAV/lib/python3.7/site-packages/machine/", line 59, in __init__
    self._client = LowLevelSlackClient()
  File "/Users/henry.hollenstain/.virtualenvs/bot-9dQm3zAV/lib/python3.7/site-packages/machine/utils/", line 14, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
  File "/Users/henry.hollenstain/.virtualenvs/bot-9dQm3zAV/lib/python3.7/site-packages/machine/clients/singletons/", line 33, in __init__
    self.rtm_client = RTMClient(token=slack_api_token, proxy=http_proxy)
  File "/Users/henry.hollenstain/.virtualenvs/bot-9dQm3zAV/lib/python3.7/site-packages/slack/rtm/", line 118, in __init__
    self.token = token.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

Placing a file with a token works.

SLACK_API_TOKEN = 'redacted' 
pipenv run python                                           
Loading .env environment variables…
Initializing Slack Machine:
    Loading settings...
    Initializing storage using backend:
    Loading plugins...

Starting Slack Machine:
    ✓ Connected to Slack
    ✓ Scheduler started
    ✓ Dispatcher started

It seems when generating the slack client

The client re imports settings already on the Machine class instead of passing in the settings to the LowLevelSlackClient:

Proposed solution

Pass settings from the Machine class into LowLevelSlackClient

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

DonDebonaircommented, Jul 24, 2020

Only after I wrote my reply, I actually saw your PR. With some adjustments it actually might work. I will have a look at your PR in the coming days, so don’t close it yet.

hhollenstaincommented, Jul 24, 2020

@DandyDev That is a great idea. I forgot you are checking for SM_ . Able to patch the os.environ dict with os.environ['SM_SLACK_API_TOKEN'] = slack_token and worked perfectly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Slack Web API
The Web API is an RPC-style collection of methods that either yield information about Slack workspaces or allows your app to enact change...
Read more >
Cannot pass pillar data to the slack engine #39783 - GitHub
Pillar data cannot be passed to the slack engine from slack or the engine config resulting in Pillar data must be formatted as...
Read more >
How to send json formatted messages to Slack through Cloud ...
Read more here. To answer your question, you can try to send the dictionary by formatting it or in a code block as...
Read more >
Abusing Slack for Offensive Operations | by Cody Thomas
Because a single user can be signed into multiple Slack workspaces in a single Slack client, all of this information is stored in...
Read more >
Getting Started With the Slack API Using Python and Flask
For simplicity, we're only going to install and use slackclient, ... Once you've signed in you can scroll down on the web API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found