`'error': 'not_allowed_token_type'` when using `xoxp` token

See original GitHub issue

Hello everyone! I’m having this error with my Slack app/bot that’s preventing it from functioning at all. The error message itself is the same as (or at least very similar to) all the RTM-related problems (like this and this) that were caused by an API change in December 2019.

However, my bot was created less than four months ago (April 2022), and I set it up using the Events API and Socket Mode. Also, as @srajiang said (and as is mentioned in multiple other places), the Events API is a replacement for the RTM API, and so doesn’t use it. Hence, this is not a duplicate of #584. The bot worked great until I discovered this error today, when I tried to start it up again after it hadn’t been running for a month or two.

The Slack SDK version

slack-bolt==1.13.0
slack-sdk==3.15.2

Python runtime version

Python 3.8.10

OS info

Ubuntu 20.04.4 LTS

Steps to reproduce:

Here’s the code to reproduce the problem (after following the setup steps in the tutorial):

app.py

(there’s literally nothing else in the directory except .git/ and .gitignore)

import os

from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
    
# The app
app = App(token=os.environ["SLACK_BOT_TOKEN"])

# Start the app
if __name__ == "__main__":
    SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
  1. Make a new Slack App with Socket Mode and Event subscriptions on
  2. Change to the app directory and run python3 app.py

Expected result:

As per the tutorial and past experience, the app should output that it’s running properly.

Actual result:

This error message shows up instead:

Failed to retrieve WSS URL: The request to the Slack API failed. (url: https://www.slack.com/api/apps.connections.open)
The server responded with: {'ok': False, 'error': 'not_allowed_token_type'}
Traceback (most recent call last):
  File "app.py", line 11, in <module>
    SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
  File "/home/user/.local/lib/python3.8/site-packages/slack_bolt/adapter/socket_mode/base_handler.py", line 46, in start
    self.connect()
  File "/home/user/.local/lib/python3.8/site-packages/slack_bolt/adapter/socket_mode/base_handler.py", line 31, in connect
    self.client.connect()
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/socket_mode/builtin/client.py", line 165, in connect
    self.wss_uri = self.issue_new_wss_url()
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/socket_mode/client.py", line 61, in issue_new_wss_url
    raise e
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/socket_mode/client.py", line 48, in issue_new_wss_url
    response = self.web_client.apps_connections_open(app_token=self.app_token)
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/web/client.py", line 1502, in apps_connections_open
    return self.api_call("apps.connections.open", http_verb="POST", params=kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 145, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 182, in _sync_send
    return self._urllib_api_call(
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 316, in _urllib_api_call
    return SlackResponse(
  File "/home/user/.local/lib/python3.8/site-packages/slack_sdk/web/slack_response.py", line 205, in validate
    raise e.SlackApiError(message=msg, response=self)
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/apps.connections.open)
The server responded with: {'ok': False, 'error': 'not_allowed_token_type'}

Any ideas about what’s going wrong, and how to fix it? If you need any more information, I will provide it. Thanks for your time!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SamMatzkocommented, Jul 18, 2022

@srajiang Oops… well, it turned out I had not stored the token in a complete form. I found another place where it was complete, and, well, that fixed it. Sorry to trouble you! I’ll close this issue now. Thanks again for your help and time! I wish I could think of these things before I post issues, but I guess my brain won’t let me ¯\_(ツ)_/¯.

0reactions
srajiangcommented, Jul 18, 2022

All good @SamMatzko - Thanks for stopping by, and glad we were able to get to the bottom if it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not allowed token type for Slack connection #964 - GitHub
U am using the "xoxb-" bot token. @robertomano24. I just went through the process myself and got the same error, it took me...
Read more >
Access tokens - Slack API
Access tokens are the keys to the Slack platform. Tokens tie together all the scopes and permissions your app has obtained, allowing it...
Read more >
Slack not_allowed_token_type error - How to send message ...
You are using the wrong Bearer Token. You should be using the bot token (xoxb). The token you are currently using is for...
Read more >
slack_sdk.errors API documentation
Error raised when an 'xoxb-' token is being used for a Slack API method that only accepts 'xoxp-' tokens. Expand source code
Read more >
Web API client - Slack
At a minimum, you need to instantiate it with a token. ... An access token (from your Slack app or custom integration -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found