Python-slack-sdk: Getting "Sessions is closed" for example for RTM

Created on 29 Oct 2019  路  5Comments  路  Source: slackapi/python-slack-sdk

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [x] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [ ] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [ ] I've read and agree to the Code of Conduct.
  • [ ] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version:
2.3.0
python version:
3.6
OS version(s):
MacOS Catalina 10.15

Steps to reproduce:

  1. Copy and pasted example from documentation
  2. Ran

(Also tested my token which works with webclient)

Expected result:

Was expecting for it to run so I can send the bot a test message but crashes immediately.

Actual result:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/chamho/Google Drive/Python Projects/um-slack_bot/test.py", line 23, in <module>
    rtmclient.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/slack/rtm/client.py", line 198, in start
    return self._event_loop.run_until_complete(future)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/slack/rtm/client.py", line 334, in _connect_and_read
    proxy=self.proxy,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 728, in _ws_connect
    proxy_headers=proxy_headers)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 357, in _request
    raise RuntimeError('Session is closed')
RuntimeError: Session is closed

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

2x docs rtm-client

Most helpful comment

Thanks for writing in about this @sushiparlour. I've just released an update to address this bug in v2.3.1. Please update and let me know if it still occurs.

All 5 comments

Thanks for writing in about this @sushiparlour. I've just released an update to address this bug in v2.3.1. Please update and let me know if it still occurs.

Mi aplicacion funcionaba y tuve el mismo error luego de actualizar el modulo slackclient2.3.0 , se corrigio instalando la version 2.3.1

Mi aplicacion funcionaba y tuve el mismo error luego de actualizar el modulo slackclient2.3.0 , se corrigio instalando la version 2.3.1

Tried updating to slackclient 2.3.1. Now 'python3 app.py' does nothing. Loads indefinitely.

I think you mentioned this document: https://slack.dev/python-slackclient/real_time_messaging.html#connecting-to-the-rtm-api

If so, it works at least for me. If you're still interested in checking this issue, could you try the latest version with the following code?

import os
# pip install slackclient==2.5.0
from slack import RTMClient


@RTMClient.run_on(event="message")
def say_hello(**payload):
    data = payload['data']
    web_client = payload['web_client']

    if 'text' in data and 'Hello' in data['text']: # see https://github.com/slackapi/python-slackclient/pull/646
        channel_id = data['channel']
        thread_ts = data['ts']
        user = data['user']

        web_client.chat_postMessage(
            channel=channel_id,
            text=f"Hi <@{user}>!",
            thread_ts=thread_ts
        )


slack_token = os.environ["SLACK_API_TOKEN"]
rtm_client = RTMClient(token=slack_token)
rtm_client.start()

Adding the following lines may be helpful to figure out what is happening to your app.

import sys
print(sys.version)
import logging
logging.basicConfig(level=logging.DEBUG)
$ python app.py 
3.6.10 (default, Mar 14 2020, 13:40:31) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)]
DEBUG:asyncio:Using selector: KqueueSelector
DEBUG:slack.rtm.client:Retrieving websocket info.
DEBUG:slack.web.slack_response:Received the following response: {'ok': True, 'url': 'wss://xxx.lb.slack-msgs.com/websocket/random-random', 'team': {'id': 'T123', 'name': 'workspace', 'domain': 'your-domain'}, 'self': {'id': 'U123', 'name': 'rtm-bot'}}
DEBUG:slack.rtm.client:The Websocket connection has been opened.

Allow me to close this issue as the team doesn't have any further actions to take on this. However, if you have something further to ask/discuss here, please feel free to reopen this.

Was this page helpful?
0 / 5 - 0 ratings