“失败的RTM连接"尝试使用RTM API连接到Slack时发生错误 [英] "Failed RTM connect" error when trying to connect to Slack with RTM API

查看:407
本文介绍了“失败的RTM连接"尝试使用RTM API连接到Slack时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Slack的中的以下Python代码迁移到2.x" github文档

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"

对于SLACK_API_TOKEN,我正在为我的应用使用 Bot用户OAuth访问令牌,位于以下位置:

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

我得到的错误如下:

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

我为什么会收到此错误?!?!?!

其他上下文:

  • 我使用的是Mac,与其他使用Windows在线上遇到问题的人不同 机器.
  • 我正在通过虚拟环境在本地运行代码,方法是 python script.py在我的终端中.
  • 我上次在12月成功运行了此程序,并且看到Slack放弃了对RTM API的支持(?)2019年12月31日?
  • 该应用程序已重新安装到我的工作区中,并且密钥没有更改.
  • 我认为这可能是我需要在api.slack.com/apps端配置/更改/设置/刷新的东西,因为它破裂了,没有发生任何代码更改.
  • 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.

为什么我要集中精力调试1.x的示例?我的代码以前使用rtm_connect/1.x并与示例代码相同的命令运行,并且没有任何代码更改停止工作.我的代码和示例代码产生相同的错误,因此我使用示例代码使调试更加容易.我想在开始迁移到2.x之前解决此问题,因此我可以从工作代码开始,然后进行一系列可能导致自身错误的更改.

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.

推荐答案

我认为此问题与Bot用户OAuth访问令牌无关,在我看来,您使用的是正确的令牌(xoxb-).但是,此问题可能与Slack应用有关.请注意,新的Slack App粒度范围不支持RTM(请参见 python客户端问题# 584 节点客户端问题#921 ).如果您想使用RTM,则应该使用OAuth创建一个经典的松弛应用范围bot.

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.

这篇关于“失败的RTM连接"尝试使用RTM API连接到Slack时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆