Skip to content

Issue with running python-slack-sdk using test application. #1316

Description

@anthonythambiah

Hi all, I am attempting to send a test message to one of my slack messages using the above SDK. Here is my code for reference. Note I've added "xxxxxx" to my channel. This is a live channel that I am using in my environment.

import os
import logging
import sys
logging.basicConfig(level=logging.DEBUG)
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])
api_response = client.api_test()

try:
    response = client.chat_postMessage(channel='xxxxxxxx', text="Hello world!")
    assert response["message"]["text"] == "Hello world!"
except SlackApiError as e:
    # You will get a SlackApiError if "ok" is False
    assert e.response["ok"] is False
    assert e.response["error"]  # str like 'invalid_auth', 'channel_not_found'
    print(f"Got an error: {e.response['error']}")

This is the following result:
Got an error: channel_not_found
or
Got an error: invalid_auth

The permissions that I am using are:
channels:manage,groups:write,im:write,mpim:write,chat:write.public,chat:write

I tried to enable the log for this as well.

DEBUG:slack_sdk.web.base_client:Sending a request - url: https://www.slack.com/api/api.test, query_params: {}, body_params: {}, files: {}, json_body: None, headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': '(redacted)', 'User-Agent': 'Python/3.7.9 slackclient/3.19.5 Darwin/21.6.0'} DEBUG:slack_sdk.web.base_client:Received the following response - status: 200, headers: {'date': 'Thu, 29 Dec 2022 20:27:29 GMT', 'server': 'Apache', 'x-powered-by': 'HHVM/4.153.1', 'access-control-allow-origin': '*', 'referrer-policy': 'no-referrer', 'x-slack-backend': 'r', 'x-slack-unique-id': 'xxxxxxxxxxxxxxxxxxxxx', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'access-control-allow-headers': 'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags', 'access-control-expose-headers': 'x-slack-req-id, retry-after', 'x-oauth-scopes': 'channels:manage,groups:write,im:write,mpim:write,chat:write.public,chat:write', 'expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'cache-control': 'private, no-cache, no-store, must-revalidate', 'pragma': 'no-cache', 'x-xss-protection': '0', 'x-content-type-options': 'nosniff', 'x-slack-req-id': 'xxxxxxxxxxxxxxxxxxxxx', 'vary': 'Accept-Encoding', 'content-type': 'application/json; charset=utf-8', 'x-envoy-upstream-service-time': '22', 'x-backend': 'main_normal main_bedrock_normal_with_overflow main_canary_with_overflow main_bedrock_canary_with_overflow main_control_with_overflow main_bedrock_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-smef', 'x-slack-shared-secret-outcome': 'no-match', 'via': 'envoy-www-iad-vayg, envoy-edge-iad-yovk', 'x-edge-backend': 'envoy-www', 'x-slack-edge-shared-secret-outcome': 'no-match', 'connection': 'close', 'transfer-encoding': 'chunked'}, body: {"ok":true,"args":{"token":"xxxxxxxxxxxxxxxxxxxxx"}} DEBUG:slack_sdk.web.base_client:Sending a request - url: https://www.slack.com/api/chat.postMessage, query_params: {}, body_params: {}, files: {}, json_body: {'channel': 'xxxxxxxxx', 'text': 'Hello world!'}, headers: {'Content-Type': 'application/json;charset=utf-8', 'Authorization': '(redacted)', 'User-Agent': 'Python/3.7.9 slackclient/3.19.5 Darwin/21.6.0'} DEBUG:slack_sdk.web.base_client:Received the following response - status: 200, headers: {'date': 'Thu, 29 Dec 2022 20:27:29 GMT', 'server': 'Apache', 'x-powered-by': 'HHVM/4.153.1', 'access-control-allow-origin': '*', 'referrer-policy': 'no-referrer', 'x-slack-backend': 'r', 'x-slack-unique-id': 'xxxxxxxxxxx', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'access-control-allow-headers': 'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags', 'access-control-expose-headers': 'x-slack-req-id, retry-after', 'x-oauth-scopes': 'channels:manage,groups:write,im:write,mpim:write,chat:write.public,chat:write', 'x-accepted-oauth-scopes': 'chat:write', 'expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'cache-control': 'private, no-cache, no-store, must-revalidate', 'pragma': 'no-cache', 'x-xss-protection': '0', 'x-content-type-options': 'nosniff', 'x-slack-req-id': 'xxxxxxxxxxxxxxxxxx', 'vary': 'Accept-Encoding', 'content-type': 'application/json; charset=utf-8', 'x-envoy-upstream-service-time': '28', 'x-backend': 'main_normal main_bedrock_normal_with_overflow main_canary_with_overflow main_bedrock_canary_with_overflow main_control_with_overflow main_bedrock_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-xdxl', 'x-slack-shared-secret-outcome': 'no-match', 'via': 'envoy-www-iad-6eo8, envoy-edge-iad-tnva', 'x-edge-backend': 'envoy-www', 'x-slack-edge-shared-secret-outcome': 'no-match', 'connection': 'close', 'transfer-encoding': 'chunked'}, body: {"ok":false,"error":"channel_not_found"} Got an error: channel_not_found

The channel itself exists as I am using it. However, I would like to know if there is anything else that I am missing which is causing this error?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions