deedy5 / duckduckgo_search

Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.
MIT License
1.12k stars 131 forks source link

IndexError: list index out of range #57

Closed KirillRepinArt closed 1 year ago

KirillRepinArt commented 1 year ago

While running this:

import os
iskaggle = os.environ.get('KAGGLE_KERNEL_RUN_TYPE', '')
from duckduckgo_search import ddg_images
from fastcore.all import *

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return L(ddg_images(term, max_results=max_images)).itemgot('image')
urls = search_images('birds', max_images=5)
urls[0]

Searching for 'birds'

I'm getting this:

IndexError Traceback (most recent call last) Cell In[2], line 2 1 urls = search_images('birds', max_images=5) ----> 2 urls[0]

File F:\Program Files (x86)\Python_3_10_6\lib\site-packages\fastcore\foundation.py:112, in L.getitem(self, idx) --> 112 def getitem(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

File F:\Program Files (x86)\Python_3_10_6\lib\site-packages\fastcore\foundation.py:116, in L._get(self, i) 115 def _get(self, i): --> 116 if isindexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i] 117 i = mask2idxs(i) 118 return (self.items.iloc[list(i)] if hasattr(self.items,'iloc') 119 else self.items.array()[(i,)] if hasattr(self.items,'array') 120 else [self.items[i] for i_ in i])

IndexError: list index out of range

Yesterday everything worked fine but to day I encounter this issue, I've tried different versions of duckduckgo_search, it might work for a bit but then it breaks again.

deedy5 commented 1 year ago

You should update version to v2.9.4

pip install -U duckduckgo_search

All previous versions no longer work.

KirillRepinArt commented 1 year ago

I have tried that also multiple times. It might work for a moment, but on the next run I'm getting this:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[3], line 2
      1 urls = search_images('airplane photos', max_images=1)
----> 2 urls[0]

File F:\Program Files (x86)\Python_3_10_6\lib\site-packages\fastcore\foundation.py:112, in L.__getitem__(self, idx)
--> 112 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

File F:\Program Files (x86)\Python_3_10_6\lib\site-packages\fastcore\foundation.py:116, in L._get(self, i)
    115 def _get(self, i):
--> 116     if is_indexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i]
    117     i = mask2idxs(i)
    118     return (self.items.iloc[list(i)] if hasattr(self.items,'iloc')
    119             else self.items.__array__()[(i,)] if hasattr(self.items,'__array__')
    120             else [self.items[i_] for i_ in i])

IndexError: list index out of range

Problem started today, yesterday everything worked fine all day.

deedy5 commented 1 year ago

ddgs version Type this command in the terminal and show me the result.

KirillRepinArt commented 1 year ago

ddgs version Type this command in the terminal and show me the result.

F:\Jupyter>ddgs version 2.9.4 Would prefer a screenshot?

deedy5 commented 1 year ago

What about ddgs images -k 'airplane photos' ?

KirillRepinArt commented 1 year ago

Using terminal?

The following is from cmd:

F:\Jupyter>ddgs images -k 'airplane photos'
Usage: ddgs [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Try 'ddgs --help' for help.

Error: No such command "photos'".

F:\Jupyter>
KirillRepinArt commented 1 year ago

I've triedddgs images -k 'airplane photos' now using Windows PowerShell and it seems to work:

PS F:\jupyter> ddgs version
2.9.4
PS F:\jupyter> ddgs images -k 'airplane photos'
1. ------------------------------------------------------------------------------
title       50 Airplane Wallpaper Backgrounds in HD for Free Download
image       http://wonderfulengineering.com/wp-content/uploads/2014/05/airplane-wallpaper-1.jpg
thumbnail   https://tse3.mm.bing.net/th?id=OIP.CSU0WYkZwY4keDZCuzMsfQHaE5&pid=Api
url         https://wonderfulengineering.com/50-airplane-wallpaper-backgrounds-in-hd-for-free-download/
height      3687
width       5582
source      Bing
deedy5 commented 1 year ago

It's not a problem with this package.

KirillRepinArt commented 1 year ago

It's not a problem with this package.

Is it possible that there are some changes regarding user's IP address? If I change my IP I'm able to execute my code and it downloads several images until it stops, then I have to change my IP address again. There seem to be a limit on the amount of requests I can send from the same IP.

deedy5 commented 1 year ago

If you have python 3.7, upgrade duckduckgo_search to v2.9.5. Maybe that's the problem.

KirillRepinArt commented 1 year ago

I'm using Python 3.10.

That's very unfortunate that it seem to break over the nigh. I tried this example in notebook:

from duckduckgo_search import ddg_images

keywords = 'liberty tree'
r = ddg_images(keywords, region='wt-wt', safesearch='Off', size=None,
               color='Monochrome', type_image=None, layout=None, license_image=None, max_results=300)
print(r)

it returns only []

Again, it seems that I can have very few requests in a given amount of time and then it cuts me off. But may be it's just me, I'll have to try something else.

deedy5 commented 1 year ago

Try to use a proxy