Invalid API key error is now in json format

This commit is contained in:
Martin
2016-06-30 17:10:07 +02:00
parent 28af106ecd
commit 4b593c8cbe
+3 -1
View File
@@ -1,4 +1,5 @@
# coding=UTF-8 # coding=UTF-8
import json
from flask import request, current_app, Response from flask import request, current_app, Response
import unidecode import unidecode
import re import re
@@ -9,8 +10,9 @@ def check_api_key():
return return
auth = request.authorization auth = request.authorization
if not auth or not auth.username in api_keys: if not auth or not auth.username in api_keys:
response = json.dumps({'status': 401, 'message': 'No valid API key provided'})
return Response( return Response(
'No valid API key provided', 401, response, 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'} {'WWW-Authenticate': 'Basic realm="Login Required"'}
) )