django芹菜工人关键字参数错误

时间:2018-06-04 08:03:43

标签: python django django-celery

我试图设置一个简单的webhook,其中传入的请求由芹菜工人处理。

这是view.py中的钩子:

@method_decorator(csrf_exempt, name='dispatch')
class SendGridCallbackView(View):
    def post(self, request, *args, **kwargs):
        print('TEST')
        req_dict = {'request': request.body}
        sendgrid_email_tracking.apply_async(kwargs=req_dict)
        return HttpResponse(status=200)

tasks.py中定义的任务:

@shared_task(base=WorkerBase, name='mailer.sendgrid-tracking-mail')
def sendgrid_email_tracking(**kwargs):
    print('GOTCHA')

从sendgrid发送测试邮件时,会打印TEST输出,但芹菜工作者会返回错误

TypeError: sendgrid_email_tracking() got an unexpected keyword argument 'request'

当我添加其他参数*args时,错误消失,但在被调用的方法中,*args**kwargs都为空

@shared_task(base=WorkerBase, name='mailer.sendgrid-tracking-mail')
def sendgrid_email_tracking(*args, **kwargs):
    print(args)     # prints -> ()
    print(kwargs)   # prints -> {}

0 个答案:

没有答案