on master help sign in
[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>

commitb10c1346d78c3562167acbcec70b5b3e74ffd9ef authorMarkus Heiser <markus.heiser@darmarit.de> dateSat 24 Jul 2021, 13:52 (5 years ago) parent7aa94b7
1 file changed+10−3
searx/engines/qwant.py+10−3
searx/engines/qwant.py+10−3
@@ -156,7 +156,10 @@ def response(resp):
156156 })
157157
158158 elif mainline_type == 'news':
159− pub_date = datetime.fromtimestamp(item['date'], None)
159+
160+ pub_date = item['date']
161+ if pub_date is not None:
162+ pub_date = datetime.fromtimestamp(pub_date)
160163 news_media = item.get('media', [])
161164 img_src = None
162165 if news_media:
@@ -192,8 +195,12 @@ def response(resp):
192195 if c:
193196 content_parts.append("%s: %s " % (gettext("Channel"), c))
194197 content = ' // '.join(content_parts)
195− length = timedelta(seconds=item['duration'])
196− pub_date = datetime.fromtimestamp(item['date'])
198+ length = item['duration']
199+ if length is not None:
200+ length = timedelta(milliseconds=length)
201+ pub_date = item['date']
202+ if pub_date is not None:
203+ pub_date = datetime.fromtimestamp(pub_date)
197204 thumbnail = item['thumbnail']
198205 # from some locations (DE and others?) the s2 link do
199206 # response a 'Please wait ..' but does not deliver the thumbnail