松弛400错误:“响应为:missing_text_or_fallback_or_attachments”

时间:2020-03-24 22:36:32

标签: python-3.x webhooks slack slack-api slack-commands

这是我的代码片段,其中我将有效负载发送到松弛的Webhook:

dictoftitle = {i: posts_to_print[i] for i in range(0, len(posts_to_print))}

response = requests.post(web_hook_url, data=json.dumps(dictoftitle))

if response.status_code != 200:
raise ValueError('Request to slack returned an error %s, the response is:\n%s '% 
(response.status_code, response.text) )

这是有效载荷的样子:

print(dictoftitle)
{0: 'When girls are the shero of the story', 1: 'Simplified global game management: Introducing Game Servers', 2: 'Google Cloud named a leader in the Forrester Wave for Public Cloud Development and Infrastructure Platforms', 3: "Modernizing Twitter's ad engagement analytics platform", 4: 'Protect users in your apps with 
multi-factor authentication', 5: 'Postponing Google Cloud Next ’20: Digital Connect', 6: 'Not just for HTTP anymore: gRPC comes to Cloud Run', 7: 'Data processing just got easier with Apps Script’s new V8 runtime', 8: 'G Suite Pro Tips: Declutter your inbox with Gmail filters', 9: 'How EBSCO delivers dynamic research services with Apigee', 10: 'Finding a problem at the bottom of the Google stack', 11: 'Best practices for Chrome Enterprise admins to enable a remote workforce', 12: 'Modern analytics made easy with new Redshift, S3 migration tools', 13: 'Local SSDs + VMs = love at first (tera)byte', 14: '재택근무 시 업무 수행과 관련된 8가 
지 도움말', 15: '使用 G Suite 居家办公的八大妙招', 16: '善用 8 大秘訣,確保在家工作時的工作效率', 17: '8 tips untuk menyelesaikan pekerjaan saat bekerja dari jarak jauh', 18: '8 mẹo để hoàn thành công việc khi làm việc tại nhà', 19: 'เคลดลบ 8 ข้อเพ่อการทำงานจากบ้านอย่างมประสทธภาพ'}

发送有效载荷时出现错误:

 Traceback (most recent call last):                                                                                                                               
  File "test3.py", line 83, in <module>                                                                                                                          
    raise ValueError('Request to slack returned an error %s, the response is:\n%s '% (response.status_code, response.text) )                                     
ValueError: Request to slack returned an error 400, the response is:                                                                                             
missing_text_or_fallback_or_attachments    

您对导致此问题的原因有任何想法吗?

1 个答案:

答案 0 :(得分:2)

您正在尝试将通用的Slack传入Webhook与发送自定义有效负载的服务一起使用吗?您将需要将其有效负载转换为Slack传入的Webhooks(https://api.slack.com/messaging/composing)接受的格式。我希望这是有道理的。如果您对此还有其他疑问,请告诉我们。