After running for a while, slackbot will inevitably crash with this error.
Traceback (most recent call last):
File "./main.py", line 27, in <module>
main()
File "./main.py", line 21, in main
slack.Bot().run()
File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/bot.py", line 37, in run
self._dispatcher.loop()
File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/dispatcher.py", line 151, in loop
self._client.parse_user_data(user)
File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/slackclient.py", line 78, in parse_user_data
self.users.update({u['id']: u for u in user_data})
File "/home/pi/slackbot/venv/lib/python3.4/site-packages/slackbot/slackclient.py", line 78, in <dictcomp>
self.users.update({u['id']: u for u in user_data})
TypeError: 'NoneType' object is not subscriptable
Some system information:
$ python --version
Python 3.4.2
$ uname -a
Linux hostname 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
$ cat /etc/issue
Raspbian GNU/Linux 8 \n \l
It seems to me that when iterating through the user_data list, it is possible to come across a None object in the list, and that trying to access the 'id' key of the (what is presumed, falsely to be a) dict results in a TypeError since the element in user_data is not in fact a dict.
A naïve fix for this would be to change the line to read:
self.users.update({u['id']: u for u in user_data if u is not None})
but I expect that there might be other code that expects user_data to not have a None in it either, and so there needs to be better filtering on elements going into the user_data list in order to enforce that only proper/expected objects make their way in there.
Let me know if you want any more info, etc.
Also, thanks for making this! It's much better than the code that slack themselves put out for working with the RTM API.
After running for a while, slackbot will inevitably crash with this error.
Some system information:
It seems to me that when iterating through the
user_data
list, it is possible to come across aNone
object in the list, and that trying to access the 'id' key of the (what is presumed, falsely to be a)dict
results in aTypeError
since the element inuser_data
is not in fact adict
.A naïve fix for this would be to change the line to read:
but I expect that there might be other code that expects
user_data
to not have aNone
in it either, and so there needs to be better filtering on elements going into theuser_data
list in order to enforce that only proper/expected objects make their way in there.Let me know if you want any more info, etc.
Also, thanks for making this! It's much better than the code that slack themselves put out for working with the RTM API.