arrrlo / Google-Images-Search

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

Time out #109

Closed AzazelHD closed 3 years ago

AzazelHD commented 3 years ago

Hi, sometimes i get this error requests.exceptions.ConnectionError: HTTPConnectionPool(host='mythirion.co.uk', port=80): Max retries exceeded with url:

And whole script crashes. How can I avoid it?

arrrlo commented 3 years ago

Hi @AzazelHD,

The simplest way to tackle this problem is to try - except gis.search(...) part in your script:

import requests

try:
    gis.search(...)
except requests.exceptions.ConnectionError:
    pass

With this quick solution your script will fetch only images from the first one till the one before the exception. The rest will be ignored because whole images fetching crashed but not your script. This should be done directly in package so only problematic image url should be ignored.

Thanks! Ivan.