微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

松弛块+发送响应在python中不起作用,即使异步也不行-仅在CURL中

如何解决松弛块+发送响应在python中不起作用,即使异步也不行-仅在CURL中

  • 代码块发送到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)来节省大量代码

关于您的问题:

  1. 确保Celery参数未进行奇怪的编码(response_url发送到messagerie并进行了编码)
  2. 确保正确使用了请求参数(例如使用json代替data ...)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。