Python slackapi:Can';不要发送附件

Python slackapi:Can';不要发送附件,python,slack,slack-api,Python,Slack,Slack Api,我试图使用Slack的Python客户端发送附件,但每次发送都失败。我也试着用测试仪发送,但还是不起作用。要么我得到{“ok”:false,“error”:“no_text”},要么如果我有text属性,则只发送文本。我就是这样做的。我也找了,但什么也没找到 attachment = json.dumps([{"attachments": [{"fallback": "Reddit Message","color": "#448aff","pretext":"You've got

我试图使用Slack的Python客户端发送附件,但每次发送都失败。我也试着用测试仪发送,但还是不起作用。要么我得到
{“ok”:false,“error”:“no_text”}
,要么如果我有text属性,则只发送文本。我就是这样做的。我也找了,但什么也没找到

       attachment = json.dumps([{"attachments": [{"fallback": "Reddit Message","color": "#448aff","pretext":"You've got a new Message!","author_name": "Reddit","author_link": "https://reddit.com","author_icon": "imageurl","title": "Reddit Message","title_link": "https://reddit.com/message/inbox","text": "This is what I know about it.","fields": [{"title": "Author:","value": str(item.author),"short": "true"},{"title": "Subject: ","value": str(item.subject),"short": "true"},{"title": "Message:","value": str(item.body),"short": "false"}],"footer": "Reddit API","footer_icon": "anotherimageurl"}]})

sc.api_call("chat.postMessage",channel="U64KWRJAU",attachments=attachment,as_user=True)

我们将不胜感激。这应该是有道理的,但我不明白为什么它不起作用。

从您的参考资料中,您需要将附件作为列表传递。您不需要在包含列表的dict中输入附件

attachment = json.dumps([
    {
        "fallback": "Reddit Message",
        "color": "#448aff",
        "pretext":"You've got a new Message!",
        "author_name": "Reddit",
        "author_link": "https://reddit.com",
        ....
    }
])

sc.api_call(
    "chat.postMessage", channel="U64KWRJAU",
    attachments=attachment, as_user=True)

但我没有发送文件。我正在发送邮件附件。邮件附件?你是说一个代码段吗?但是我得到:
{u'ok':False,u'error':u'no_text'}
你需要向提供
text
属性。这是强制性的。如果你只是想要附件的话,你可以发送一个空字符串。文档上没有说如果我有它不需要的借口吗。此外,如果我填写了文本字段,则不会发送附件