python3.4 bug

see also https://github.com/mozilla/http-observatory/pull/86/files
This commit is contained in:
Thorsten
2017-09-06 21:51:01 +02:00
parent c9aedc4b18
commit 10cec5bbea

View File

@@ -1,14 +1,15 @@
import logging import logging
import time import time
from functools import wraps from functools import wraps
from json import JSONDecodeError import json
import requests import requests
from lxml import etree, html from lxml import etree, html
from requests import HTTPError from requests import HTTPError
search_list = [] search_list = []
if not hasattr(json, 'JSONDecodeError'):
json.JSONDecodeError = ValueError
class RateLimitingError(HTTPError): class RateLimitingError(HTTPError):
pass pass
@@ -69,7 +70,7 @@ def fetch_all_searx_engines():
return searxes return searxes
@retry(ExceptionToCheck=(RateLimitingError, JSONDecodeError)) @retry(ExceptionToCheck=(RateLimitingError, json.JSONDecodeError))
def searx(text): def searx(text):
global search_list global search_list
if not search_list: if not search_list:
@@ -88,7 +89,7 @@ def searx(text):
raise RateLimitingError(response=response, request=response.request) raise RateLimitingError(response=response, request=response.request)
try: try:
response = response.json() response = response.json()
except JSONDecodeError as e: except json.JSONDecodeError:
# "maintenance" they say... # "maintenance" they say...
search_list.pop() search_list.pop()
raise raise