【发布时间】:2023-03-19 16:26:02
【问题描述】:
我尝试使用 webhook 向我的 slack 频道发送 POST 请求,但无济于事。
无论我做什么,它总是返回一个错误的请求。
有没有办法在不使用 webhook 的情况下向 slack 发送 POST 请求?
编辑:我正在使用的代码
import json
import urllib.request
#import botocore.requests as requests
def lambda_handler(event, context):
webhook=event['webhook']
#response = urllib.request.urlopen(message)
#print(response)
slack_URL = 'https://hooks.slack.com/services/mywebhookurl'
# req = urllib.request.Request(SLACK_URL, json.dumps(webhook).encode('utf-8'))
json=webhook
json=json.encode('utf-8')
headers={'Content-Type': 'application/json'}
#urllib.request.add_data(data)
req = urllib.request.Request(slack_URL, json, headers)
response = urllib.request.urlopen(req)
【问题讨论】:
-
如何使用 webhook?你能显示你的代码吗?
-
我添加了我的代码,但问题是我总是收到 HTTP 400 Error Bad Request。我已经调试了好几天,但没有任何效果,所以我想看看是否有其他方法可以做到这一点。
标签: python aws-lambda bots slack