mirror of
https://github.com/searxng/searxng.git
synced 2024-11-17 18:00:12 +01:00
[fix] convert json engine result attributes to string - closes #1006
This commit is contained in:
parent
a065fcdcc9
commit
0969e50c5b
@ -2,6 +2,7 @@ from collections import Iterable
|
|||||||
from json import loads
|
from json import loads
|
||||||
from sys import version_info
|
from sys import version_info
|
||||||
from searx.url_utils import urlencode
|
from searx.url_utils import urlencode
|
||||||
|
from searx.utils import to_string
|
||||||
|
|
||||||
if version_info[0] == 3:
|
if version_info[0] == 3:
|
||||||
unicode = str
|
unicode = str
|
||||||
@ -111,14 +112,22 @@ def response(resp):
|
|||||||
content = query(result, content_query)[0]
|
content = query(result, content_query)[0]
|
||||||
except:
|
except:
|
||||||
content = ""
|
content = ""
|
||||||
results.append({'url': url, 'title': title, 'content': content})
|
results.append({
|
||||||
|
'url': to_string(url),
|
||||||
|
'title': to_string(title),
|
||||||
|
'content': to_string(content),
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
for url, title, content in zip(
|
for url, title, content in zip(
|
||||||
query(json, url_query),
|
query(json, url_query),
|
||||||
query(json, title_query),
|
query(json, title_query),
|
||||||
query(json, content_query)
|
query(json, content_query)
|
||||||
):
|
):
|
||||||
results.append({'url': url, 'title': title, 'content': content})
|
results.append({
|
||||||
|
'url': to_string(url),
|
||||||
|
'title': to_string(title),
|
||||||
|
'content': to_string(content),
|
||||||
|
})
|
||||||
|
|
||||||
if not suggestion_query:
|
if not suggestion_query:
|
||||||
return results
|
return results
|
||||||
|
@ -7,6 +7,7 @@ import re
|
|||||||
from babel.dates import format_date
|
from babel.dates import format_date
|
||||||
from codecs import getincrementalencoder
|
from codecs import getincrementalencoder
|
||||||
from imp import load_source
|
from imp import load_source
|
||||||
|
from numbers import Number
|
||||||
from os.path import splitext, join
|
from os.path import splitext, join
|
||||||
from random import choice
|
from random import choice
|
||||||
import sys
|
import sys
|
||||||
@ -336,3 +337,14 @@ def new_hmac(secret_key, url):
|
|||||||
return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest()
|
return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest()
|
||||||
else:
|
else:
|
||||||
return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest()
|
return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def to_string(obj):
|
||||||
|
if isinstance(obj, basestring):
|
||||||
|
return obj
|
||||||
|
if isinstance(obj, Number):
|
||||||
|
return unicode(obj)
|
||||||
|
if hasattr(obj, '__str__'):
|
||||||
|
return obj.__str__()
|
||||||
|
if hasattr(obj, '__repr__'):
|
||||||
|
return obj.__repr__()
|
||||||
|
Loading…
Reference in New Issue
Block a user