arrrlo / Google-Images-Search

[PYTHON] Search for image using Google Custom Search API and resize & crop afterwards
MIT License
178 stars 34 forks source link

"Request contains an invalid argument." when try to download a big number of images #141

Closed ahmadalghadban closed 2 years ago

ahmadalghadban commented 2 years ago

I've downloaded 20 images successfully but when tried to download 100-300 images I've got the following error

 "Request contains an invalid argument."
 Traceback (most recent call last):
  File "c:\Users\User\Desktop\imagesD.py", line 21, in <module>
    gis.next_page()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\google_images_search\fetch_resize_save.py", line 218, in next_page     
    self.search(*self._get_data())
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\google_images_search\fetch_resize_save.py", line 151, in search        
    self._search_images(*self._get_data())
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\google_images_search\fetch_resize_save.py", line 177, in _search_images    for url, referrer_url in self._google_custom_search.search(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\google_images_search\google_api.py", line 83, in search
    res = self._query_google_api(search_params, cache_discovery)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\google_images_search\google_api.py", line 49, in _query_google_api     
    cx=self._custom_search_cx, **search_params).execute()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\http.py", line 915, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://customsearch.googleapis.com/customsearch/v1?cx=XXX&q=orange&searchType=image&num=10&start=201&imgType=photo&fileType=jpg%7Cpng&safe=high&k
ey=XXX&alt=json returned "Request contains an invalid argument.". Details: "Request
 contains an invalid argument.">
arrrlo commented 2 years ago

Hi,

Ok, with every request two parameters are sent, among others: num and start And by looking at your error trace, I see start=201. And there is an error response.

So I guess Google doesn't allow for start parameter to be bigger than 200? This should be checked.