如何通过http设置芹菜任务调用http_headers

问题描述:

我想通过HTTP使用芹菜类的HttpDispatch进行任务调用,但我需要设置授权标头。我怎样才能做到这一点?如何通过http设置芹菜任务调用http_headers

from celery.task.http import HttpDispatch 
request = HttpDispatch(
    url='http://example.com/multiply', 
    method='GET', {10}) 
request.dispatch() 

您将需要继承HttpDispatch并重新实​​现http_headers财产法。该酒店用于HttpDispatch

class CustomHttpDispatch(HttpDispatch): 

@property 
def http_headers(self): 
    headers = { 
     'User-Agent': self.user_agent, 
     'Authorization': 'XXX'} 

    return headers 
+0

谢谢你的帮忙! –