From 018da184124870d21ff5608c7b09b33a369bd9df Mon Sep 17 00:00:00 2001 From: iceboy Date: Sun, 29 Oct 2017 13:23:20 -0700 Subject: [PATCH] Fixes #379 --- vj4/handler/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vj4/handler/base.py b/vj4/handler/base.py index 6f4cfed7..987fe5f1 100644 --- a/vj4/handler/base.py +++ b/vj4/handler/base.py @@ -270,7 +270,14 @@ async def binary(self, data, content_type='application/octet-stream', file_name= @property def prefer_json(self): - for d in accept.parse(self.request.headers.get('Accept')): + accept_header = self.request.headers.get('Accept') + try: + parse_result = accept.parse(accept_header) + except (ValueError, IndexError): + # the accept library throws bogus exceptions + _logger.warning('Unparsable accept header: %s', accept_header) + return False + for d in parse_result: if d.media_type == 'application/json': return True elif d.media_type == 'text/html' or d.all_types: