Post to slack with Python 3

I will summarize the procedure from python to posting to slack. This is useful for notifying the completion of time-consuming processing and information during execution (errors, etc.).

Rough flow

--Set up Incoming Webhook in slack --Post from python to the URL of the Incoming Webhook

Set up Incoming Webhook in slack

Go to the Incoming Webhook Settings page (https://my.slack.com/services/new/incoming-webhook/) Select the channel you want to post to and click "Add Incoming WebHooks Integration"

スクリーンショット_2016-09-21_23_44_40.png

Copy the webhook URL

スクリーンショット_2016-09-21_23_47_46.png

Click "Save Settings"

スクリーンショット_2016-09-21_23_52_59.png

Post from python to the URL of the Incoming Webhook

Install slackweb to easily implement POST

#Install if pip is not installed
$ sudo easy_install pip

#Install slack web
$ sudo pip install slackweb

postToSlack.py


#coding: UTF-8

import slackweb

slack = slackweb.Slack(url="URL of the copied webhook")
slack.notify(text="From python to slack")

Run python script

$ python postToSlack.py

Check the posted results

スクリーンショット 2016-09-22 0.01.21.png

reference

-Post to Slack in Python

Recommended Posts

Post to slack with Python 3
Post from Python to Slack
Post to Slack in Python
Easily post to twitter with Python 3
Image characters and post to slack (python slackbot)
Post youtube soaring title to twitter with python3
Sample to send slack notification with python lambda
[Python] Mention to multiple people with Slack API
Post an article with an image to WordPress with Python
Flow to complete Slack authentication with Flask (Python)
Connect to BigQuery with Python
Post to Slack via Subscriber
POST json with Python3 script
Connect to Wikipedia with Python
Post to Twitter using Python
Switch python to 2.7 with alternatives
Write to csv with Python
POST messages from python to Slack via incoming webhook
Post Jenkins console output to Slack
Python: How to use async with
Link to get started with python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Post from python to facebook timeline
Output to csv file with Python
[Lambda] [Python] Post to Twitter from Lambda!
[Python] POST wav files with requests [POST]
Quine Post with Qiita API (Python)
Convert list to DataFrame with python
MP3 to WAV conversion with Python
To do tail recursion with Python2
How to get started with Python
Post multiple Twitter images with python
Post to slack in Go language
What to do with PYTHON release?
Post images from Python to Tumblr
Unable to install Python with pyenv
How to use FTP with Python
How to calculate date with python
[Nanonets] How to post Memo [Python]
I want to debug with Python
Send experiment results (text and images) to slack with Python
Post a message to Google Hangouts Chat with a thread (Python)
FizzBuzz with Python3
Updated to Python 2.7.9
Try to reproduce color film with Python
Scraping with Python
Try logging in to qiita with Python
Convert memo at once with Python 2to3
Statistics with python
Memo to ask for KPI with python
Simple Slack API client made with Python
Scraping with Python
Output color characters to pretty with python
Python with Go
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
Send a message from Python to Slack
Post a message from IBM Cloud Functions to Slack in Python
POST variously with Python and receive with Flask