如何通过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
谢谢你的帮忙! –