From ca57c7421b7f57f9c5ebb22ec0be241494a5e0eb Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 24 Jul 2021 13:52:36 +0200 Subject: [PATCH 1/2] [fix] qwant engine - prevent exception on date/time value is None Has been reported in [1], error messages:: Error Error: ValueError Percentage: 0 Parameters: () File name: searx/engines/qwant.py:159 Function: response Code: pub_date = datetime.fromtimestamp(item['date'], None) Error Error: TypeError Percentage: 0 Parameters: ('an integer is required (got type NoneType)',) File name: searx/engines/qwant.py:196 Function: response Code: pub_date = datetime.fromtimestamp(item['date']) Fix timedelta from seconds to milliseconds [1], error message:: Error Error: TypeError Percentage: 0 Parameters: ('unsupported type for timedelta seconds component: NoneType',) File name: searx/engines/qwant.py:195 Function: response Code: length = timedelta(seconds=item['duration']) [1] https://github.com/searxng/searxng/issues/222 Signed-off-by: Markus Heiser --- searx/engines/qwant.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py index 97e461177..deac55cf9 100644 --- a/searx/engines/qwant.py +++ b/searx/engines/qwant.py @@ -156,7 +156,10 @@ def response(resp): }) elif mainline_type == 'news': - pub_date = datetime.fromtimestamp(item['date'], None) + + pub_date = item['date'] + if pub_date is not None: + pub_date = datetime.fromtimestamp(pub_date) news_media = item.get('media', []) img_src = None if news_media: @@ -192,8 +195,12 @@ def response(resp): if c: content_parts.append("%s: %s " % (gettext("Channel"), c)) content = ' // '.join(content_parts) - length = timedelta(seconds=item['duration']) - pub_date = datetime.fromtimestamp(item['date']) + length = item['duration'] + if length is not None: + length = timedelta(milliseconds=length) + pub_date = item['date'] + if pub_date is not None: + pub_date = datetime.fromtimestamp(pub_date) thumbnail = item['thumbnail'] # from some locations (DE and others?) the s2 link do # response a 'Please wait ..' but does not deliver the thumbnail From fe67f1478f2f6b0939f378e7a1c65b7303f35763 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 24 Jul 2021 14:45:32 +0200 Subject: [PATCH 2/2] [fix] qwant engine - prevent API locale exception on lang 'all' Has been reported in [1], error message:: Error Error: searx.exceptions.SearxEngineAPIException Percentage: 0 Parameters: ('API error::locale must be a string,locale must be one of the following values: en_gb, en_ie, en_us, en_ca, en_in, en_my, en_au, en_nz, cy_gb, gd_gb, de_de, de_ch, de_at, fr_fr, br_fr, fr_be, fr_ch, fr_ca, fr_ad, fc_ca, ec_ca, co_fr, es_es, es_ar, es_cl, es_co, es_mx, es_pe, es_ad, ca_es, ca_ad, ca_fr, eu_es, eu_fr, it_it, it_ch, pt_br, pt_pt, pt_ad, nl_be, nl_nl, pl_pl, zh_hk, zh_cn, fi_fi, bg_bg, et_ee, hu_hu, da_dk, nb_no, sv_se, ko_kr, th_th, cs_cz, ro_ro, el_gr',) File name: searx/engines/qwant.py:114 Function: response Code: raise SearxEngineAPIException('API error::' + msg) [1] https://github.com/searxng/searxng/issues/222 Signed-off-by: Markus Heiser --- searx/engines/qwant.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py index deac55cf9..8d03d8324 100644 --- a/searx/engines/qwant.py +++ b/searx/engines/qwant.py @@ -84,14 +84,16 @@ def request(query, params): ) # add language tag - if params['language'] != 'all': + if params['language'] == 'all': + params['url'] += '&locale=en_us' + else: language = match_language( params['language'], # pylint: disable=undefined-variable supported_languages, language_aliases, ) - params['url'] += '&locale=' + language.replace('-', '_') + params['url'] += '&locale=' + language.replace('-', '_').lower() params['raise_for_httperror'] = False return params @@ -144,8 +146,8 @@ def response(resp): mainline_items = row.get('items', []) for item in mainline_items: - title = item['title'] - res_url = item['url'] + title = item.get('title', None) + res_url = item.get('url', None) if mainline_type == 'web': content = item['desc']