Skip to content

Instantly share code, notes, and snippets.

@trimkadriu
Created November 27, 2020 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trimkadriu/4cffd108101230321ccf2af83713249d to your computer and use it in GitHub Desktop.
Save trimkadriu/4cffd108101230321ccf2af83713249d to your computer and use it in GitHub Desktop.
Send Slack message with web-hooks on Python
import json
import requests
webhook_url = "" #Add the webhook here
slack_data = {"text": "This is a test message", "channel": "<channel-name> or <@person>"}
response = requests.post(
webhook_url, data = json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment