LoginSignup
3
0

More than 3 years have passed since last update.

pythonでslack apiのchannels.historyが使えない

Posted at

問題

pip install slackclientsをしてから、
slack apiのchannels.historyを以下のように叩いても

history.py
import slack

slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
res = sc.api_call("channels.history", json={
        "channel": "CEB1BL1MM",
    })
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'channel_not_found', 'warning': 'missing_charset', 'response_metadata': {'warnings': ['missing_charset']}}

とエラーが返ってきて、値が取得できない。
エラーメッセージを検索してもいまいち原因がわからないし、設定にはまちがいがないはず。
他のapiは正常に動く(例えばchat.post_messageとか)

原因(というか要因)

インストールしたslack clientが2.0.0以上だとできなかった。
しかたがないので
pip uninstall slackclientsしたのち
pip install slackclient==1.3.0と古いバージョンを入れなおしたら、正常に動いた

その際はapiの呼び方が変わるので注意

history.py
response = sc.api_call(
        "channels.history",
        channel= "CEB1BL1MM"
    )

まとめ

slack apiのv2自体が二週間前(2019/05/14時点)にリリースされたもののため、バグがのこっていたということだろうか・・・
治ってほしい

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0