summaryrefslogtreecommitdiff
path: root/searx/engines/duckduckgo_images.py
diff options
context:
space:
mode:
authorMarc Abonce Seguin <marc-abonce@mailbox.org>2019-04-13 00:17:32 -0500
committerMarc Abonce Seguin <marc-abonce@mailbox.org>2019-04-13 00:38:37 -0500
commit3e1c2153f75adbf3e5d9eab0b0d4e567893e8d64 (patch)
tree09ae4868d930940abc52ee60b7b5fc8edc9d3d57 /searx/engines/duckduckgo_images.py
parent34d85c8c3c2191818544ecd5e6c0508590657a2b (diff)
downloadsearxng-3e1c2153f75adbf3e5d9eab0b0d4e567893e8d64.tar.gz
searxng-3e1c2153f75adbf3e5d9eab0b0d4e567893e8d64.zip
[fix] duckduckgo images requests
Diffstat (limited to 'searx/engines/duckduckgo_images.py')
-rw-r--r--searx/engines/duckduckgo_images.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/searx/engines/duckduckgo_images.py b/searx/engines/duckduckgo_images.py
index 8c46ec92d..89924b71c 100644
--- a/searx/engines/duckduckgo_images.py
+++ b/searx/engines/duckduckgo_images.py
@@ -35,9 +35,12 @@ site_url = 'https://duckduckgo.com/?{query}&iar=images&iax=1&ia=images'
# run query in site to get vqd number needed for requesting images
# TODO: find a way to get this number without an extra request (is it a hash of the query?)
-def get_vqd(query):
- res = get(site_url.format(query=urlencode({'q': query})))
+def get_vqd(query, headers):
+ query_url = site_url.format(query=urlencode({'q': query}))
+ res = get(query_url, headers=headers)
content = res.text
+ if content.find('vqd=\'') == -1:
+ raise Exception('Request failed')
vqd = content[content.find('vqd=\'') + 5:]
vqd = vqd[:vqd.find('\'')]
return vqd
@@ -47,7 +50,7 @@ def get_vqd(query):
def request(query, params):
# to avoid running actual external requests when testing
if 'is_test' not in params:
- vqd = get_vqd(query)
+ vqd = get_vqd(query, params['headers'])
else:
vqd = '12345'
@@ -74,7 +77,7 @@ def response(resp):
try:
res_json = loads(content)
except:
- return []
+ raise Exception('Cannot parse results')
# parse results
for result in res_json['results']: