Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack sensor - TypeError: expected string or buffer #50

Open
rufik opened this issue May 22, 2019 · 4 comments
Open

Slack sensor - TypeError: expected string or buffer #50

rufik opened this issue May 22, 2019 · 4 comments
Labels

Comments

@rufik
Copy link

rufik commented May 22, 2019

I'm getting this error while activating sensor/trigger for slack messages. Am I missing something to be configured? I can successfully invoke services like post_message, channels.list, users.list, etc.

May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,082 ERROR [-] Traceback (most recent call last):
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,083 ERROR [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 362, in <module>
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,084 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,085 ERROR [-] obj.run()
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,085 ERROR [-]   File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 219, in run
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,086 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,087 ERROR [-] self._sensor_instance.setup()
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,087 ERROR [-]   File "/opt/stackstorm/packs/slack/sensors/slack_sensor.py", line 56, in setup
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,088 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,088 ERROR [-] self._populate_cache(user_data=self._api_call('users.list'),
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,089 ERROR [-]   File "/opt/stackstorm/packs/slack/sensors/slack_sensor.py", line 260, in _api_call
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,089 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,090 ERROR [-] result = json.loads(result)
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,090 ERROR [-]   File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,091 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,092 ERROR [-] return _default_decoder.decode(s)
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,092 ERROR [-]   File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,093 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,094 ERROR [-] obj, end = self.raw_decode(s, idx=_w(s, 0).end())
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,094 ERROR [-] TypeError
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,095 ERROR [-] :
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,096 ERROR [-] expected string or buffer
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,096 ERROR [-]
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,097 INFO [-] Stopping trigger watcher
May 22 23:50:52 etabox st2sensorcontainer[9235]: 2019-05-22 23:50:52,098 INFO [-] Invoking cleanup on sensor
@blag
Copy link
Contributor

blag commented May 23, 2019

Code is here:

result = json.loads(result)

The result from slackclient.api_call when trying to do a users.list needs to be a string and it wasn't.

This may happen if there was an error when trying to run users.list. So ensure the configured SlackBot that StackStorm is using has permissions to run users.list. To further troubleshoot, patch the StackStorm code in /opt/stackstorm/packs/slack/sensors/slack_sensor.py to dump the returned result using self._logger.debug() to the sensor log.

@rufik
Copy link
Author

rufik commented May 23, 2019

Thanks for your tips. I've printed result var content and type - it looks like it isn't string type. It's just <type 'dict'>. I've took a look into slackclient lib, it seems to perform json conversion already:
https://github.com/slackapi/python-slackclient/blob/66f1fb5f40a8a358360a6d7e471dec776d276aa6/slackclient/client.py#L189

So this line:

result = json.loads(result)

needs to be deleted. I've commented it out and sensor is working fine now :)

@arm4b arm4b added the question label May 24, 2019
@DjOyhom
Copy link

DjOyhom commented Oct 7, 2020

Hi, im trying to use the sensor, but i don't know why st2 don't exec the trigger, do you have any idea of how to config the slack pack ?

@moet78
Copy link

moet78 commented Nov 21, 2020

confirmed you need to remove / comment out line 260 in slack_sensor.py, or the sensor will bug out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants