“Failed RTM connect” error when trying to connect to Slack with RTM API

允我心安 提交于 2020-05-13 13:41:18

问题


I'm using the following Python code from Slack's "Migrating to 2.x" github docs

from slackclient import SlackClient

slack_token = os.environ["SLACK_API_TOKEN"]
client = SlackClient(slack_token)

def say_hello(data):
    if 'Hello' in data['text']:
        channel_id = data['channel']
        thread_ts = data['ts']
        user = data['user']

        client.api_call('chat.postMessage',
            channel=channel_id,
            text="Hi <@{}>!".format(user),
            thread_ts=thread_ts
        )

if client.rtm_connect():
    while client.server.connected is True:
        for data in client.rtm_read():
            if "type" in data and data["type"] == "message":
                say_hello(data)
else:
    print "Connection Failed"

For the SLACK_API_TOKEN, I am using the Bot User OAuth Access Token for my app, found here:

The error I am getting is the following:

Failed RTM connect
Traceback (most recent call last):
  File "/Users/.../slackbot/slackbot_env/lib/python3.8/site-packages/slackclient/client.py", line 140, in rtm_connect
    self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
  File "/Users/.../slackbot/slackbot_env/lib/python3.8/site-packages/slackclient/server.py", line 168, in rtm_connect
    raise SlackLoginError(reply=reply)
slackclient.server.SlackLoginError
Connection Failed

Why am I getting this error?!?!?!

Other context:

  • I am on a Mac, unlike others who have had issues online using Windows machines.
  • I am running the code locally, in a virtual env, via python script.py in my terminal.
  • I last successfully ran this in December, and have seen that Slack dropped support for the RTM API (?) Dec 31st 2019?
  • The app has been reinstalled to my workspace, and the keys did not change.
  • I think it may be something I need to configure/change/set/refresh on the api.slack.com/apps side, since it broke without any code changes occurring.

Why am I focusing on debugging the example for 1.x? My code was previously working using rtm_connect / 1.x using the same commands as the example code, and without any code changes it has stopped working. My code and the example code yield the same errors, so I'm using the sample code to make debugging easier. I'd like to fix this before starting the process of migrating to 2.x, so I can start with working code before embarking on a long series of changes that can introduce their own errors.


回答1:


I not sure if this is the reason, but I ran into the same issues before. The answer I found on the Slack Github is that new xoxob-* doesn't support RTM.

Please reference this web: - https://github.com/slackapi/python-slackclient/issues/326.

So I use my OAuth Access Token instead of Bot User OAuth Access Token.




回答2:


I do not think this issue is related to the Bot User OAuth Access Token, in my view you are using the right one (xoxb-). However, this issue might be related to the Slack App. Note that RTM isn't supported for the new Slack App granular scopes (see python client issue #584 and node client issue #921). If you want to use RTM, you should create rather a classic slack app with the OAuth Scope bot.



来源:https://stackoverflow.com/questions/59955434/failed-rtm-connect-error-when-trying-to-connect-to-slack-with-rtm-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!