Python-slack-sdk: RTM client running in docker was disconnected immediately after first connection

Created on 27 Feb 2019  路  2Comments  路  Source: slackapi/python-slack-sdk

Description

Running a very simple RTM client from docker, while rtm_connect() return True indicating a successful connection, the subsequent call to rtm_read() failed immediately.

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

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

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

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

Bug Report

This is the simple script , it runs without any problem if it is not in docker container

if slack_client.rtm_connect():
    print("Connected to Slack")
    while True:
        slack_client.rtm_read()
        time.sleep(READ_WEBSOCKET_DELAY)

Reproducible in:

If run the script (see above) from a docker container, gets the following error

slack-bot       | DEBUG: Starting new HTTPS connection (1): slack.com:443
slack-bot       | DEBUG: https://slack.com:443 "POST /api/rtm.start HTTP/1.1" 200 5759
slack-bot       | DEBUG: RTM connected
slack-bot       | DEBUG: RTM disconnected
slack-bot       | Connected to Slack
slack-bot       | Traceback (most recent call last):
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/slackclient/server.py", line 278, in websocket_safe_read
slack-bot       |     data += "{0}\n".format(self.websocket.recv())
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 313, in recv
slack-bot       |     opcode, data = self.recv_data()
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 330, in recv_data
slack-bot       |     opcode, frame = self.recv_data_frame(control_frame)
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 343, in recv_data_frame
slack-bot       |     frame = self.recv_frame()
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 377, in recv_frame
slack-bot       |     return self.frame_buffer.recv_frame()
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 361, in recv_frame
slack-bot       |     self.recv_header()
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 309, in recv_header
slack-bot       |     header = self.recv_strict(2)
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 396, in recv_strict
slack-bot       |     bytes_ = self.recv(min(16384, shortage))
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 452, in _recv
slack-bot       |     return recv(self.sock, bufsize)
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 112, in recv
slack-bot       |     "Connection is already closed.")
slack-bot       | websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
slack-bot       |
slack-bot       | During handling of the above exception, another exception occurred:
slack-bot       |
slack-bot       | Traceback (most recent call last):
slack-bot       |   File "/bot/bot.py", line 76, in <module>
slack-bot       |     run()
slack-bot       |   File "/bot/bot.py", line 71, in run
slack-bot       |     parseSlackRTM(slack_client.rtm_read())
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/slackclient/client.py", line 235, in rtm_read
slack-bot       |     json_data = self.server.websocket_safe_read()
slack-bot       |   File "/usr/local/lib/python3.7/site-packages/slackclient/server.py", line 296, in websocket_safe_read
slack-bot       |     "Unable to send due to closed RTM websocket"
slack-bot       | slackclient.server.SlackConnectionError: Unable to send due to closed RTM websocket

slackclient version: latest

python version: 3.7

OS version(s): Linux

Steps to reproduce:

The docker image is built from the Dockerfile below:

FROM python:3.7.2-alpine3.8
RUN apk update && apk upgrade && \
    apk add --no-cache && apk add build-base && apk add libffi-dev && \
    apk add libxml2-dev && apk add libxslt-dev && apk add openssl-dev
RUN mkdir /app
COPY requirements.txt /app/
WORKDIR /app

The only package in requirements.txt is slackclient,

Most helpful comment

I hit this same problem today when I did an update to one of my Docker containers which has been working successfully for many months. I tracked it down to the recent release of the websocket-client==0.55.0 Python package.

https://pypi.org/project/websocket_client/#history

Adding pip install "websocket-client==0.54.0" before installing slackclient==1.3.0 works around the problem for me, with no other changes to the installed Python packages.

All 2 comments

I hit this same problem today when I did an update to one of my Docker containers which has been working successfully for many months. I tracked it down to the recent release of the websocket-client==0.55.0 Python package.

https://pypi.org/project/websocket_client/#history

Adding pip install "websocket-client==0.54.0" before installing slackclient==1.3.0 works around the problem for me, with no other changes to the installed Python packages.

Thanks for reporting this issue! I'm closing it as a duplicate of #385. I've opened #387 as a temp fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

naveenjafer picture naveenjafer  路  4Comments

charlesreid1 picture charlesreid1  路  3Comments

divyatman picture divyatman  路  4Comments

sofya-salmanova picture sofya-salmanova  路  5Comments

ErikKalkoken picture ErikKalkoken  路  3Comments