1

我想使用 celery 中的 HttpDispatch 类通过 HTTP 进行任务调用,但我需要设置 Authorization 标头。我怎样才能做到这一点?

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

1 回答 1

3

您将需要子类HttpDispatch化并重新实现http_headers属性方法。该属性在内部使用HttpDispatch

class CustomHttpDispatch(HttpDispatch):

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

    return headers
于 2016-01-21T13:27:47.433 回答