简体   繁体   English

松弛 api 无效的身份验证错误构建松弛机器人

[英]slack api invalid auth error building slack bot

I'm trying to write a python script that helps me automate my agile environment but every time I try to run the code I get this error.我正在尝试编写一个 python 脚本来帮助我自动化我的敏捷环境,但每次我尝试运行代码时都会收到此错误。 " slack_sdk.errors.SlackApiError: The request to the Slack API failed. The server responded with: {'ok': False, 'error': 'invalid_auth'} " this is my code “ slack_sdk.errors.SlackApiError:对 Slack API 的请求失败。服务器响应:{'ok': False, 'error': 'invalid_auth'}”这是我的代码

import slack
import os
from pathlib import Path
from dotenv import load_dotenv


env_path = Path('D:\Work\FinHive\Mini Youssef')/ 'Env.env'
load_dotenv(dotenv_path=env_path)
client = slack.WebClient(token=os.environ['SLACK_TOKEN'])

client.chat_postMessage(channel='#test', text="this works")

It seems that you already have set up a token for your application, but double check that the value in the environment variable matches what you have in your slack application.您似乎已经为您的应用程序设置了一个令牌,但请仔细检查环境变量中的值是否与您的 slack 应用程序中的值匹配。

If the value matches, then the next culprit would be permission for your bot to post on the channel.如果该值匹配,那么下一个罪魁祸首将是您的机器人在频道上发帖的权限。 You can see in the API documentation for postMessage that your bot needs the chat:write scope from your App page -> OAuth & Permissions -> Scroll down to scopes.您可以在postMessage的 API 文档中看到您的机器人需要聊天:从您的应用页面写入scope -> OAuth 和权限 -> 向下滚动到范围

Finaly, make sure that the bot user is in the #test channel.最后,确保机器人用户在#test 频道中。 You may need to grant your bot the channels:join scope, and invite them to #test.您可能需要向您的机器人授予频道:加入 scope,并邀请他们参加#test。

Did you create your bot as new app or classic app?您将机器人创建为新应用还是经典应用? Which token (xoxb-* or xoxp-*) are you using in your app?您在应用中使用的是哪个令牌(xoxb-* 或 xoxp-*)? I would suggest to validate your token https://api.slack.com/methods/chat.postMessage/test .我建议验证您的令牌https://api.slack.com/methods/chat.postMessage/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM