Skip to content
Permalink
Browse files

[fix] duckduckgo images requests

  • Loading branch information...
MarcAbonce committed Apr 13, 2019
1 parent 34d85c8 commit 3e1c2153f75adbf3e5d9eab0b0d4e567893e8d64
Showing with 8 additions and 5 deletions.
  1. +7 −4 searx/engines/duckduckgo_images.py
  2. +1 −1 tests/unit/engines/test_duckduckgo_images.py
@@ -35,9 +35,12 @@

# 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']:
@@ -41,7 +41,7 @@ def test_response(self):
self.assertRaises(AttributeError, duckduckgo_images.response, '[]')

response = mock.Mock(text='If this error persists, please let us know: ops@duckduckgo.com')
self.assertEqual(duckduckgo_images.response(response), [])
self.assertRaises(Exception, duckduckgo_images.response, response)

json = u"""
{

0 comments on commit 3e1c215

Please sign in to comment.
You can’t perform that action at this time.