diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2021-07-24 13:52:36 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2021-07-24 14:48:14 +0200 |
commit | ca57c7421b7f57f9c5ebb22ec0be241494a5e0eb (patch) | |
tree | 1dd5e66b0238119f5f0164ffff01d8828ab76f4b /searx/engines | |
parent | ea0f4346b13527c601bfcfb1f5d17a13b3dfc15c (diff) | |
download | searxng-ca57c7421b7f57f9c5ebb22ec0be241494a5e0eb.tar.gz searxng-ca57c7421b7f57f9c5ebb22ec0be241494a5e0eb.zip |
[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 <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/qwant.py | 13 |
1 files 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 |