Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having the error "'error': 'not_authed'" #561

Closed
4 of 9 tasks
windowshopr opened this issue Nov 14, 2019 · 3 comments
Closed
4 of 9 tasks

Having the error "'error': 'not_authed'" #561

windowshopr opened this issue Nov 14, 2019 · 3 comments

Comments

@windowshopr
Copy link

Description

I followed the setup tutorial (created an app, added a bot, etc.), then I copy my Bot User OAuth Access Token to the following code:

import os
import slack

slack_token = os.environ.get("xoxb-THE_REST_OF_AUTH_IS_HERE")
client = slack.WebClient(token=slack_token)

client.chat_postMessage(
  channel="#MY_CHANNEL_IS_HERE",
  text="Hello from your app! :tada:"
)

...and I'm getting the following error:

    raise e.SlackApiError(message=msg, response=self)
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'not_authed'}

How do I "Auth" my bot's token then?

I did see a similar issue from another user, but no answer was provided to fix it.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version: 2.3.1

python version: 3.6

OS version(s): Windows 10

Steps to reproduce:

  1. I had to change the "os.environ[]" to "os.environ.get()" to make it work without a keyerror.
  2. Followed 2 different tutorials and tried a myriad of different codes and other how to's.

Expected result:

To be able to post a message to my Slack channel from my python script.

Actual result:

The mentioned error

Attachments:

@windowshopr
Copy link
Author

Scratch that, I'm using the below code to post messages to my channel:

import requests
import json

web_hook_url = 'https://hooks.slack.com/services/THE_REST_OF_MY_APPS_URL' # Need to encrypt this value in future

slack_msg = {'text': 'Alert from Python'}

requests.post(web_hook_url, data=json.dumps(slack_msg))

@darthsalad
Copy link

try this:

import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from dotenv import load_dotenv

load_dotenv()
key = os.environ.get('token') #token in a .env file 
client = WebClient(token = key) #or if not in a .env file, (token="xoxb-res_of_the_token")
result = client.chat_postMessage(
        channel='#push-notifications', 
        text="Hello world"
    )

@darthsalad
Copy link

was trying today and got the error, and after seeing the errors in the docs, it was not getting initialised properly and the getenv was returning a "NoneType" object
had forgotten to add this line:

load_dotenv()

fml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants