def post(self, request):
"""Receive a list of changed user IDs from Dropbox and process each."""
# Make sure this is a valid request from Dropbox
logger.debug('[Dropbox - View - Webhook] received a webhook')
signature = request.environ.get('HTTP_X_DROPBOX_SIGNATURE')
try:
request_body_size = int(request.environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
pass
request_body = request.environ['wsgi.input'].read(request_body_size)
request_hashed = hmac.new( APP_SECRET.encode("utf-8"),
request_body,
sha256).hexdigest()
if not hmac.compare_digest(signature, request_hashed):
error_url = '{}?status=error'.format(self.get_redirect(request))
return redirect(error_url)
try:
data = json.loads(request_body.decode('utf-8'))
for user in data['delta']['users']:
logger.debug('[Dropbox - View - webhook] \
firedTrigger for user with id:{}'.format(user))
tasks.fireTrigger(user)
except json.decoder.JSONDecodeError:
pass
return HttpResponse()
评论列表
文章目录