问题描述
- 将代码块发送到Slack-正确显示为Slack。
- 单击按钮,我正在获得交互式事件Webhook。
- webhook将200 OK返回松弛状态,而不是在将异步POST调度到
import pyspark.sql.functions as f from pyspark.sql.window import Window percentages=df\ .withColumn('% Increase Feb-20',((f.col('2020-02')-f.col('2020-01'))/f.col('2020-01')))\ .withColumn('% Increase Mar-20',((f.col('2020-03')-f.col('2020-02'))/f.col('2020-02')))\ .withColumn('% Increase Apr-20',((f.col('2020-04')-f.col('2020-03'))/f.col('2020-03')))\ .withColumn('% Increase May-20',((f.col('2020-05')-f.col('2020-04'))/f.col('2020-04')))\ .withColumn('% Increase Jun-20',((f.col('2020-06')-f.col('2020-05'))/f.col('2020-05')))\ .withColumn('% Increase Jul-20',((f.col('2020-07')-f.col('2020-06'))/f.col('2020-06')))\ .withColumn('% Increase Aug-20',((f.col('2020-08')-f.col('2020-07'))/f.col('2020-07')))\ .withColumn('% Increase Sep-20',((f.col('2020-09')-f.col('2020-08'))/f.col('2020-08')))\ display(percentages)``` The error I got is ``` cannot resolve '`2020-02`' given input columns: [Description,2020-09,name_id,Metrics,Partner];```
之前
- 从Webhook函数返回200 ack之后,返回消息将发布到
response_url
- Slack响应404到
response_url
- 当卷曲在python之外时,相同的响应URL会起作用。
我不明白为什么当在python之外的curl中使用相同的response_url时,slack会用404拒绝发布的返回消息。
我的webhook处理器:
response_url
发送
的异步芹菜任务def slack_webhook(request):
json_dict = json.loads(request.body.decode('utf-8'))
token = json_dict['token'] if 'token' in json_dict else None
message = json_dict['message'] if 'message' in json_dict else None
trigger_id = json_dict['trigger_id'] if 'trigger_id' in json_dict else None
response_url = json_dict['response_url'] if 'response_url' in json_dict else None
actions = json_dict['actions'] if 'actions' in json_dict else None
for action in actions:
print(f"** received action {action['action_id']}")
print(f"** response_url: {response_url}")
print(f"** trigger_id: {trigger_id}")
payload = {
"replace_original": True,"text": "Success!",}
# async via Celery...
send_slack_interactive_response.delay(response_url,payload,trigger_id)
return HttpResponse(status=200)
此功能在404时失败。但是,当我使用@app.task(bind=True,retry_kwargs={'max_retries': 10,'countdown': 5})
def send_slack_interactive_response(self,response_url,trigger_id):
print(f"** -> response_url: {response_url}")
print(f"** -> trigger_id: {trigger_id}")
if response_url and payload and trigger_id:
headers = {"Content-Type": "application/json"}
payload['trigger_id'] = trigger_id
print(json.dumps(payload))
r = requests.post(response_url,data=payload,headers=headers)
print(r.__dict__)
,response_url
并使用命令行trigger_id
创建完全相同的POST时,它就起作用了。
我在做什么错了?
解决方法
只需对您的代码进行注释:您可以进行token = json_dict.get("token",None)
来节省大量代码
关于您的问题:
- 确保Celery参数未进行奇怪的编码(response_url发送到messagerie并进行了编码)
- 确保正确使用了请求参数(例如使用
json
代替data
...)