Title: Slack send attachment returning 500 error
Tags: python;python-3.x;slack;slack-api
Question: I am trying to send an attachment to a Slack web hook.
I have followed the API documentation and can send a simple message. When I try send an attachment I get a 500 error, I presume there is an issue with my payload but I cannot work it out for the life of me.
How do I get the attachment to post successfully?
import slackweb
slack = slackweb.Slack(url='WEB HOOK URL HERE')
slack.notify(text="Maguro is a sushi")
attachments = []
attachment = {
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#36a64f",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Optional text that appears within the attachment",
"fields": [
{
"title": "Priority",
"value": "High",
"short": False
}
],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
attachments.append(attachment)
slack.notify(attachments=attachments)

Here is the accepted answer: You're missing two required fields in your Slack message with attachments: text and channel. You also need to lowercase the value of the short field to false.
See the corrected message here in Slack's message tester:
"text": "You need this field",
"channel": "C########",
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#36a64f",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Optional text that appears within the attachment",
"fields": [
{
"title": "Priority",
"value": "High",
"short": false
}
],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
Create a JSON structure including those two fields and your attachments variable, and you should be good to go.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:05/30/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><python-3.x><slack><slack-api>', 'Title': 'Slack send attachment returning 500 error', 'ViewCount': 410, 'id': 50601632, 'user_AboutMe': None, 'user_AccountId': 12097713.0, 'user_DisplayName': 'Piers Thomas', 'user_Reputation': 307.0, 'user_Views': 63.0, 'user_id': 8840275.0}}