Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Can't start rtmbot in bash on ubuntu on windows with virtualenv #63

Closed
4 tasks done
nmat opened this issue Oct 20, 2016 · 20 comments
Closed
4 tasks done

Can't start rtmbot in bash on ubuntu on windows with virtualenv #63

nmat opened this issue Oct 20, 2016 · 20 comments

Comments

@nmat
Copy link

nmat commented Oct 20, 2016

  • 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.

Description

Can't start rtmbot.py in bash on ubuntu on windows using virtualenv and any python version.

Reproducible in:

  • This is reproducible in the sample project.
    RTMBot version: git
    Python version: 3.4.3/2.7.6
    OS Version: Windows 10 Version 1607 (OS Build 14393.321)

Steps to reproduce:

  1. Create a new virtualenv on windows 10 using bash on ubuntu on windows
  2. Activate session
  3. Follow instructions on github website
  4. Try to start rtmbot.py using: ./rtmbot.py or python rtmbot.py

Expected result:

rtmbot to start

Actual result:

Error message comes up. See below. (Tested on 2 different computers with same result and error)

Attachments:

Traceback (most recent call last): File "rtmbot.py", line 26, in <module> bot.start() File "/home/xxx/git/python-rtmbot/rtmbot/core.py", line 78, in start self._start() File "/home/xxx/git/python-rtmbot/rtmbot/core.py", line 65, in _start for reply in self.slack_client.rtm_read(): File "/home/xxx/virtualenv/slack-environment/local/lib/python2.7/site-packages/slackclient/_client.py", line 120, in rtm_read json_data = self.server.websocket_safe_read() File "/home/xxx/virtualenv/slack-environment/local/lib/python2.7/site-packages/slackclient/_server.py", line 138, in websocket_safe_read data += "{0}\n".format(self.websocket.recv()) AttributeError: 'NoneType' object has no attribute 'recv'

Traceback (most recent call last): File "./rtmbot.py", line 26, in <module> bot.start() File "/home/xxx/bottest/python-rtmbot/rtmbot/core.py", line 78, in start self._start() File "/home/xxx/bottest/python-rtmbot/rtmbot/core.py", line 65, in _start for reply in self.slack_client.rtm_read(): File "/home/xxx/virtualenv/slack-bot/lib/python3.4/site-packages/slackclient/_client.py", line 120, in rtm_read json_data = self.server.websocket_safe_read() File "/home/xxx/virtualenv/slack-bot/lib/python3.4/site-packages/slackclient/_server.py", line 138, in websocket_safe_read data += "{0}\n".format(self.websocket.recv()) AttributeError: 'NoneType' object has no attribute 'recv'

@dkshadow38
Copy link

I second Matt's conclusion. I have been attempting the exact same thing. I can get the slack bot running fine on my windows machine, but when i attempt a vm host using ubuntu 14 and 16, i get the same error.

@pepedocs
Copy link

Make sure your config file is in the right permissions for rtmbot to load it.

Also what happens if you do this?

python rtmbot.py -c /path/to/rtmbot.conf

@nmat
Copy link
Author

nmat commented Oct 21, 2016

The config file is located in the same directory.

Running: python rtmbot.py -c /path/to/rtmbot.conf gives the exact same error.

It might be possible that this has to do with how bash on ubuntu on windows works. But I am not 100% sure.

@pepedocs
Copy link

Possibly. The reason why I asked this is because that exact python exception happens when the websocket creation failed. For example the token is invalid. The token is in the config file in this case.

@nmat
Copy link
Author

nmat commented Oct 21, 2016

yeah I have tested using normal powershell mode with python and that works just fine.

but there could be a problem with sockets and how bash on ubuntu on windows works. This might be fixed in the 16.04 preview but I do not have access to that for testing unfortunately.

@pepedocs
Copy link

pepedocs commented Oct 21, 2016

I've tested it with the following and it works fine;

OS: Ubuntu 14.04.5 LTS (on top of virtualbox mac)
Python: 2.7.6
rtmbot: origin/HEAD (or master)

@nmat
When i tried cutting off network connection in my vbox NAT interface, suddenly I get the same error as above. I've seen these types of errors before in python-slackclient and they are not properly propagated to the app. For example, rmbot uses python-slackclient and when some websocket exception happens in python-slackclient, they are not propagated/raised upto rtmbot, thus you still see rtmbot trying to connect even though the actual socket was not created.

Example related issue: slackapi/python-slack-sdk#101

In any case, make sure your network interface is properly setup for example must be able to connect to the internet do a test perhaps.

@nmat
Copy link
Author

nmat commented Oct 22, 2016

@pepedocs
That does sound right. I wonder though if this has something to do with how WSL actually works with the interfaces. Note that I have tested using django with virtualenv and python3 without any problems.

However checking for interfaces in /sbin/ifconfig using WSL shows nothing. Could this be the issue where the system does not really hold any interface where the socket can be bound?

WSL is still in preview however it would be good to know if it actually is that which is causing the problems.

@pepedocs
Copy link

pepedocs commented Oct 22, 2016

@nmat

You may try the following to get more info about possible errors when creating the socket;

  1. Check if your token is valid using slack's rtm start api.
curl https://slack.com/api/rtm.start?token=YOURTOKENHERE

You should get a json response with at least the following key and values;
"ok": "true"
"url": "wss://mpmulti-k5lo.slack-msgs.com/websocket/SOMELONGRANDOMIDHERE"

Check for errors here.

  1. To check for more possible errors, you can try connecting to that wss url value above using python's websocket-client which is the one used by python-slackclient. Note you have to install python websocket-client module.

Type "python" in terminal

>> from websocket import create_connection
>> ws = create_connection("wss://mpmulti-k5lo.slack-msgs.com/websocket/SOMELONGRANDOMIDHERE")
>> ws
<websocket._core.WebSocket object at 0x10faaef50>
>> ws.recv
<bound method WebSocket.recv of <websocket._core.WebSocket object at 0x10faaef50>>

The last line with the "bound" string is the one being referred in the above exception in your first post. Here as you noticed the websocket is created properly and it was able to create "recv" method as well. In your case "ws" did not exist thus the error.

@nmat
Copy link
Author

nmat commented Oct 25, 2016

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/xxx/virtualenv/starterbot/lib/python3.4/site-packages/websocket/_core.py", line 489, in create_connection websock.connect(url, **options) File "/home/xxx/virtualenv/starterbot/lib/python3.4/site-packages/websocket/_core.py", line 216, in connect options.pop('socket', None)) File "/home/xxx/virtualenv/starterbot/lib/python3.4/site-packages/websocket/_http.py", line 67, in connect sock = _open_socket(addrinfo_list, options.sockopt, options.timeout) File "/home/xxx/virtualenv/starterbot/lib/python3.4/site-packages/websocket/_http.py", line 103, in _open_socket sock.setsockopt(*opts) OSError: [Errno 22] Invalid argument

I have looked a bit on the upcoming release of bash on ubuntu on windows though and there is quite a few changes coming in regarding connections and more for sockets. But like I said I can't test it since I am not on the insider preview. :(

@pepedocs
Copy link

Hi @nmat,

Have you tried the test I described above?

I don't think there is a problem in bash or ubuntu. Bash doesn't have anything to do with sockets.

@pepedocs
Copy link

@nmat If that stack trace you've just posted is the output of the test I described (please add more info), then it looks like the error is some sort of python incompatibility. Can you please try the test I described both for py 2.7 and 3.4?

@gstewart86
Copy link

I'm also experiencing OP's issue on Ubuntu 14.04:
Description: Ubuntu 14.04.5 LTS
Release: 14.04

Python version 2.7.12

Error in question:
Traceback (most recent call last):
File "/usr/local/bin/rtmbot", line 9, in
load_entry_point('rtmbot==0.4.0', 'console_scripts', 'rtmbot')()
File "/usr/local/lib/python2.7/dist-packages/rtmbot/bin/run_rtmbot.py", line 31, in main
bot.start()
File "/usr/local/lib/python2.7/dist-packages/rtmbot/core.py", line 99, in start
self._start()
File "/usr/local/lib/python2.7/dist-packages/rtmbot/core.py", line 86, in _start
for reply in self.slack_client.rtm_read():
File "/usr/local/lib/python2.7/dist-packages/slackclient/_client.py", line 120, in rtm_read
json_data = self.server.websocket_safe_read()
File "/usr/local/lib/python2.7/dist-packages/slackclient/_server.py", line 138, in websocket_safe_read
data += "{0}\n".format(self.websocket.recv())
AttributeError: 'NoneType' object has no attribute 'recv'

The tests you list earlier seem to function properly for me, at least for python 2.7:

from websocket import create_connection
ws = create_connection("")
ws.recv
<bound method WebSocket.recv of <websocket._core.WebSocket object at 0x7f976650b090>>

I'd be happy to provide any further information if needed.

@vladan
Copy link

vladan commented Dec 29, 2016

Hi, I also had troubles starting the bot on python 3.5. I traced the error to the websocket client, got this exact error websocket-client/websocket-client#227.

After applying this (quick and dirty) fix I got everything working:

diff --git a/slackclient/_server.py b/slackclient/_server.py
index c48f1a7..4873417 100644
--- a/slackclient/_server.py
+++ b/slackclient/_server.py
@@ -2,10 +2,10 @@ from slackclient._slackrequest import SlackRequest
 from slackclient._channel import Channel
 from slackclient._user import User
 from slackclient._util import SearchList, SearchDict
-from ssl import SSLError
 
 from websocket import create_connection
 import json
+import ssl
 
 
 class Server(object):
@@ -86,7 +86,8 @@ class Server(object):
 
     def connect_slack_websocket(self, ws_url):
         try:
-            self.websocket = create_connection(ws_url)
+            sslopt = {"cert_reqs": ssl.CERT_NONE}
+            self.websocket = create_connection(ws_url, sslopt=sslopt)
             self.websocket.sock.setblocking(0)
         except:
             raise SlackConnectionError
@@ -136,7 +137,7 @@ class Server(object):
         while True:
             try:
                 data += "{0}\n".format(self.websocket.recv())
-            except SSLError as e:
+            except ssl.SSLError as e:
                 if e.errno == 2:
                     # errno 2 occurs when trying to read or write data, but more
                     # data needs to be received on the underlying TCP transport

@mikegrima
Copy link

It's interesting... I just started seeing this error this morning (12/29) on both OS X and Ubuntu. However, the error appears to be intermittent.

I'm seeing this on version 0.3.0 of the rtmbot, with python 3.5.

@Scribbles4U
Copy link

Scribbles4U commented Jan 4, 2017

I was receiving this same error on CentOS 6 with Python 2.7.8; errors suggested issues with SNI. Upgrading Python to the newer 2.7.13 branch resolved the issue, I suspect it's because Python's 3.4 SSL module has been backported in 2.7.9 and above.

@mikegrima
Copy link

Hi @vladan ! Did you ever submit that as a PR to websocket-client/websocket-client ?

I still get the errors every now and then for some reason... (I haven't tried the patch, but will the next time I encounter the issue.

@vladan
Copy link

vladan commented Feb 14, 2017

Hey @mikegrima, I didn't submit a PR because the error is the way slackclient uses websocket-client, I just saw what needs to be done in slackclient to get it running with python3, which slackclient officialy doesn't support :(

If I find more time to get busy with slackclient I could help with the python3 support, for now I'll use this dirty thing I patched.

@rsgoldfarb
Copy link

rsgoldfarb commented Jun 17, 2017

I apologize if this is too simplistic or not directly related to this thread, but after cloning the github files I don't see rtmbot.py anywhere. Is this file supposed to be created from the cloning process or is there a command to generate it?

@dimabutyrin
Copy link

Funny thing, I had the same error. Found solution here, in the comments, after I did curl https://slack.com/api/rtm.start?token=YOURTOKENHERE I realized that my token is restricted and can be used only from my local IP, added ec2 node external IP to the list.
It would be helpful if I could see auth error instead of the traceback.

@Roach
Copy link
Contributor

Roach commented Mar 30, 2018

This issue should be fixed when using slackclient 1.2.0+

@Roach Roach closed this as completed Mar 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants