問題
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時点)にリリースされたもののため、バグがのこっていたということだろうか・・・
治ってほしい