Giter Site home page Giter Site logo

arrrlo / google-images-search Goto Github PK

View Code? Open in Web Editor NEW
172.0 172.0 34.0 256 KB

[PYTHON] Search for image using Google Custom Search API and resize & crop afterwards

License: MIT License

Python 100.00%
api crop download google google-images image search

google-images-search's People

Contributors

arpitjain099 avatar arrrlo avatar bradleyfowler123 avatar fuchsia80 avatar hussainity avatar isaa-ctaylor avatar mneira10 avatar reteps avatar santahey avatar sebastianchr avatar siewlinyap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

google-images-search's Issues

Cannot use num higher than 10

The Google Custom Search API is limited to 10 returns per call, your documentation states up to 49 is supported, however this is not the case from what i can tell. Can you update to utilize start parameter and allow up for 100 results with 10 requests?

Error Handling

There is no way of error handling The Quota exceeded for quota metric error raised by googleapiclient error inside the module
File "googleapiclient\http.py", line 907, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 429 when requesting https://customsearch.googleapis.com/customsearch/v1?cx=xxx=Ugh%2C&searchType=image&num=1&start=1&imgType=photo&fileType=jpg&safe=off&key=xxx&alt=json returned "Quota exceeded for quota metric 'Queries' and limit 'Queries per day' of service 'customsearch.googleapis.com'
Is there a way I can catch the Maximum Query's Per day instead of Excepting all errors the module could raise as Maximum Query's?

not sure of to proceed with image size

TypeError: Parameter "imgSize" value "huge|large|xlarge|xxlarge" is not an allowed value in "['imgSizeUndefined', 'HUGE', 'ICON', 'LARGE', 'MEDIUM', 'SMALL', 'XLARGE', 'XXLARGE']"

I get this exception, by following the documentation and writing this as search params :

        _search_params = {
            'q': f"{artist_name}",
            'num': 1-10,
            'safe': 'off',
            'fileType': 'jpg|png',
            'imgType': 'face|photo',
            'imgSize': 'huge|large|xlarge|xxlarge'
            }

Can you point out what's the problem here ?

Thanks !

fileType specifier appears to be broken

Hello,
I am experimenting with this module and found that even though in _search_params i specified
'fileType': 'png'
it still safes as jpg. The same seems to happen for
'fileType': 'gif'

Kind regards

Using imgType lineart doesn't return any results

When using the lineart term for the imgType parameter, no results seem to be downloaded. The code used is shown below:

from google_images_search import GoogleImagesSearch

gis = GoogleImagesSearch('our_api_key', 'our_project_cx')

_search_params = {
	'q': 'house',
	'num': 1,
        'imgType': 'lineart'
}

gis.search(search_params=_search_params, path_to_dir='/home/administrator/Pictures/')

Without this search term the code functions as expected

A question about API key

dear all,

I have a problem when I run the following code:
_gis.search(search_params=search_params, path_to_dir='/path/', width=500, height=500)

and the error I get is:
HttpError: <HttpError 400 when requesting https://www.googleapis.com/discovery/v1/apis/customsearch/v1/rest?key=your_dev_api_key returned "API key not valid. Please pass a valid API key.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'API_KEY_INVALID', 'domain': 'googleapis.com', 'metadata': {'service': 'customsearch.googleapis.com'}}]">

Any idea what went wrong?

Type error

Hello,

I receive the below error when running your sample code in python 3.8:

Traceback (most recent call last):
File "image_search.py", line 15, in
gis.search(search_params=_search_params, path_to_dir='/img/', width=500, height=500)
File "/home/lturidev/.local/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py", line 151, in search
self._search_images(*self._get_data())
File "/home/lturidev/.local/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py", line 177, in _search_images
for url in self._google_custom_search.search(
File "/home/lturidev/.local/lib/python3.8/site-packages/google_images_search/google_api.py", line 79, in search
res = self._query_google_api(search_params, cache_discovery)
File "/home/lturidev/.local/lib/python3.8/site-packages/google_images_search/google_api.py", line 42, in _query_google_api
self._google_build = discovery.build(
File "/usr/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/lib/python3.8/site-packages/googleapiclient/discovery.py", line 222, in build
content = _retrieve_discovery_doc(
File "/usr/lib/python3.8/site-packages/googleapiclient/discovery.py", line 273, in _retrieve_discovery_doc
resp, content = http.request(actual_url)
File "/usr/lib/python3.8/site-packages/httplib2/init.py", line 1948, in request
(response, content) = self._request(
File "/usr/lib/python3.8/site-packages/httplib2/init.py", line 1621, in _request
(response, content) = self._conn_request(
File "/usr/lib/python3.8/site-packages/httplib2/init.py", line 1528, in _conn_request
conn.connect()
File "/usr/lib/python3.8/site-packages/httplib2/init.py", line 1309, in connect
sock.connect((self.host, self.port))
File "/usr/lib/python3.8/site-packages/socks.py", line 406, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "/usr/lib/python3.8/site-packages/socks.py", line 357, in __negotiatehttp
while resp.find("\r\n\r\n")==-1:
TypeError: argument should be integer or bytes-like object, not 'str'

I also get a similar error when trying the below in CLI:

gimages search -q puppie

Thank you for your help.

Regards,
Laszlo Turi

image_search1.txt

unable to import GoogleImagesSearch

this is my exact input/output. seems to be a more internal error?

>>> from google_images_search import GoogleImagesSearch

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\saman\AppData\Local\Programs\Python\Python36\lib\site-packages\google_images_search\__init__.py", line 1, in <module> from google_images_search.fetch_resize_save import \ File "C:\Users\saman\AppData\Local\Programs\Python\Python36\lib\site-packages\google_images_search\fetch_resize_save.py", line 2, in <module> import curses File "C:\Users\saman\AppData\Local\Programs\Python\Python36\lib\curses\__init__.py", line 13, in <module> from _curses import * ModuleNotFoundError: No module named '_curses'

Continuously return results of the first search

The engine continuously return results of the very first search even if I set cache_discovery=False in params:

search_params = {
            'q': query,
            'num': 20,
            'safe': 'off'
        }

gis.search(search_params=search_params, cache_discovery=False)

BTW query is not the same in each trying - it's visually noticeable in code debugging (I'm once a several minutes getting random url from first 20 results from random word of word list).

UnkownApiNameOrVersion: name: customsearch version: v1

I'm trying to use this search api to pull images into a BytesIO object.
Code:

from google_images_search import GoogleImagesSearch
from io import BytesIO

gis = GoogleImagesSearch(token,engineid)
# token is my google cloud api key token
# engineid is what i'm struggling with, I've set it to my Custom Search Engine ID, 
# I've also set it to my google cloud service account name. I don't know what to set it to.

search_params = {
  "q":"hello",
  "num":1,
  "safe":"off",
  "imgType":"photo",
}

byteobj = BytesIO()

byteobj.seek(0)

gis.search(search_params)

try:
  image = gis.results()[0]
except Exception as e:
  print(f"Something broke. Dunno, heres the error:\n{e}\n{str(e)}")
  return

image.copy_to(byteobj)

byteobj.seek(0)
# Do other stuff to the byte object

When I run this, I get the error:

 File "/home/sky/discord-bots/skybot/src/cogs/google.py", line 37, in imageSearch
   gis.search(search_params)
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py", line 151, in search
   self._search_images(*self._get_data())
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py", line 177, in _search_images
   for url in self._google_custom_search.search(
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/google_images_search/google_api.py", line 80, in search
   res = self._query_google_api(search_params, cache_discovery)
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/google_images_search/google_api.py", line 43, in _query_google_api
   self._google_build = discovery.build(
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 131, in positional_wrapper
   raise TypeError(message)
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/googleapiclient/discovery.py", line 282, in build
   developerKey=developerKey,
 File "/home/sky/discord-bots/skybot/lib/python3.8/site-packages/googleapiclient/discovery.py", line 398, in _retrieve_discovery_doc
   http=None,
googleapiclient.errors.UnknownApiNameOrVersion: name: customsearch  version: v1

What can I do to fix this?

I can’t get it to work

I am sorry I am very stoopid and I can’t seem like to get this right. Where can I download the image for the path to get it to my project or have it locally downloaded would be best. Again not very smart
I am going to add a little thingy to this thread on my pc cause I am on my phone rn

ModuleNotFoundError: No module named '_curses'

Hi, I tried using your example project for saving google images to BytesIO but the program doesn't get very far, because in the first line I already get this error:


File "C:\Users\shaya\AppData\Local\Programs\Python\Python39\lib\site-packages\google_images_search\__init__.py", line 1, in <module>
    from google_images_search.fetch_resize_save import \
  File "C:\Users\shaya\AppData\Local\Programs\Python\Python39\lib\site-packages\google_images_search\fetch_resize_save.py", line 2, in <module>
    import curses
  File "C:\Users\shaya\AppData\Local\Programs\Python\Python39\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ModuleNotFoundError: No module named '_curses'

I hope you can help me.

None returned by gis.search()

Hi, sorry if this is a stupid question, but it is my first time using the google API and I am not sure where I made the mistake.

After executing:

    gis = GoogleImagesSearch(API_KEY, PROJECT_CX)
    _search_params = {
        'q': 'cat',
        'num': 10,
    }
    result = gis.search(_search_params)

result is None.

API_KEY is my api-key and PROJECT_CX is my custom search engine ID that can be found above the tick box where image search should be enabled. Or what exactly is the Project_cx supposed to be?

The Google API site shows me that there is some traffic coming through, but gis.search() seems to return "None" whatever I am doing.

Can you help me out if I made a mistake or any hint on why None is returned?

(Also, not sure if this is important: I had a "curses"-module import error, at the beginning. It was gone after "pip install windows-curses")

cheers,
Sven

Adding a rights param

Hey,

I am looking at this list - https://developers.google.com/custom-search/v1/cse/list

and I realize that one of the crucial ones seems to be rights.

Is it that unless we add that to the _search_params_keys, it’ll not be accepted as a parameter?

Or does your code accept arbitrary params?

If the former, I can try to add rights as a key and send over a PR.

Thanks!

After a SSLError It no longer saves images with a custom filename

if you have a for loop to download multiple images and it tries to download a word and gets a SSLError all the images it downloads afterwards will not have a custom filename (this is sample code)
arr = ["test", "Hey", "Heavy"]
for word in arr:
_search_params['q'] = arr[i]
try:
gAPI.search(search_params=_search_params, path_to_dir="ImageCache", custom_image_name=str(i))
except Exception as e:
print(e)
i += 1
image

Expected Behavior:

After the SSLError it continues to save files with a custom image name

Actual Behavior:

Continues to download Images but without a custom image name.
My guess is because it does not delete the failed image that had the SSLError
it fails to make a new image of that name because the image already exists because it has a custom file name and instead just makes the filename the URL instead of the custom file name because it already exists.

Unable to import

Hey, everytime I run- from google_images_search import GoogleImagesSearch, I am shown the following error:

image
image
Could you please help me? I have tried reinstalling google_core.api multiple times but I am still unable to use this api. Thank you in advance.

Paging via Start doesn't work properly.

I believe there is a bug in the pagination. I cannot get it fetch more than 10 items. the second call always resets the start and fetches either the same results or only the first result. I tried with both the start search_param and the next page method. I notice in your tests, you do not test the pagination.

Help needed. My code doesn't download the image.

Hi, I'm trying to get an image from the Creative Commons library using a custom Google search engine. I have selected the Creative Commons website in the sites to search list, but when I run the program it doesn't find any images. When I switched to search the whole web option the same thing happened.
I have got a super simple script:
gis = GoogleImagesSearch('My_key', ' Search engine ID ')

_search_params = {
'q': 'dog',
'num': 10,
'safe': 'off',
'fileType': 'png',
'imgType': 'clipart',
'imgSize': 'HUGE',
'imgDominantColor': 'teal'
}

gis.search(search_params=_search_params)
print(gis.search(search_params=_search_params))

Output:
None #that is what it prints

Also if I don't care about some of the parameters should I leave them blank or are they obligatory?

What am I doing wrong? Maybe my configuration is wrong?
It seems that the library is working correctly for other people so I want to thank you for creating this tool.
I hope you can help me.
Thanks!
Ernests

Pillow Installation error

I'm trying to install Google-Images-Search so I follow the instructions and when running pip install Google-Images-Search from Window's command prompt a bunch of files start installing as usual. Then it reaches this lines:

Building wheels for collected packages: Pillow
  Building wheel for Pillow (setup.py) ... error
ERROR: Command errored out with exit status 1:
  (A few dozen lines of errors)

The headers or library files could not be found for zlib,
  a required dependency when compiling Pillow from source.

  Please see the install instructions at:
     https://pillow.readthedocs.io/en/latest/installation.html
  
  ERROR: Failed building wheel for Pillow

I don't get why this error occurs. At first I thought that it might be a problem with another package so I tried to install it on a brand new virtual environment with no luck. This is also really odd since I already have Pillow installed on my PC (Yes, I did try uninstalling Pillow). Why is this happening?

getting http error

Hi,
I'm trying this code:

from google_images_search import GoogleImagesSearch
apikey = '...'
projkey = '...'


gis = GoogleImagesSearch(apikey, projkey)

_search_params = {
    'q': 'puppy',
    'num': 10,
    'safe': None,
    'fileType': None,
    'imgType': None,
    'imgSize': None,
    'imgDominantColor': None,
    'rights': None
    
}
gis.search(search_params = _search_params)

and getting this error:

---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
<ipython-input-9-528c4e385abf> in <module>
     16 
     17 }
---> 18 gis.search(search_params = _search_params)
     19 
     20 

/opt/conda/envs/fastai/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py in search(self, search_params, path_to_dir, width, height, custom_image_name, cache_discovery)
    149             self._search_params['num'] = num
    150 
--> 151             self._search_images(*self._get_data())
    152 
    153             if len(self._search_result) >= self._number_of_images \

/opt/conda/envs/fastai/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py in _search_images(self, search_params, path_to_dir, width, height, cache_discovery)
    175         i = 0
    176         threads = []
--> 177         for url in self._google_custom_search.search(
    178             search_params, cache_discovery
    179         ):

/opt/conda/envs/fastai/lib/python3.8/site-packages/google_images_search/google_api.py in search(self, params, cache_discovery)
     77 
     78         search_params = self._search_params(params)
---> 79         res = self._query_google_api(search_params, cache_discovery)
     80 
     81         results = res.get('items', [])

/opt/conda/envs/fastai/lib/python3.8/site-packages/google_images_search/google_api.py in _query_google_api(self, search_params, cache_discovery)
     45                 cache_discovery=cache_discovery)
     46 
---> 47         return self._google_build.cse().list(
     48             cx=self._custom_search_cx, **search_params).execute()
     49 

/opt/conda/envs/fastai/lib/python3.8/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/opt/conda/envs/fastai/lib/python3.8/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
    913             callback(resp)
    914         if resp.status >= 300:
--> 915             raise HttpError(resp, content, uri=self.uri)
    916         return self.postproc(resp, content)
    917 

HttpError: <HttpError 400 when requesting https://customsearch.googleapis.com/customsearch/v1?cx=52424915884&q=puppy&searchType=image&num=10&start=1&safe=off&key=...T_w&alt=json returned "Request contains an invalid argument.". Details: "Request contains an invalid argument.">

The code does not know how to handle Max retries exceeded error

The code does not know how to handle Max retries exceeded error. Sometimes this happens when program with GSI actively access a site, and it blocks for exceeding the number of hits per unit of time. We get this error:
HTTPSConnectionPool(host='gate.undelete.news', port=443): Max retries exceeded with url ----- there valid URL with valid picture.

View image url's

Good Day

So glad to see someone made it possible to download images from google search.

I installed Google-Images-Search with pip and ran the command:

gimages search -q puppies -d /opt/ -w 500 -h 500 -s large

To test and got the following:

TypeError: Parameter "imgSize" value "large" is not an allowed value in "[u'imgSizeUndefined', u'HUGE', u'ICON', u'LARGE', u'MEDIUM', u'SMALL', u'XLARGE', u'XXLARGE']"

  • Do i do something wrong as a test?
  • How can i only return image url's?

Thank You

Albertus Geyser

Failed to establish a new connection: [Errno 11001] getaddrinfo failed

This is a great project!

I am currently using it, but after it successfully downloaded a few images, I met this exception:

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000020135627A48>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

Feel like Google might be throttling me but I've added sleep code and it doesn't work. Any ideas?

Error on Attempt

I am sure I am missing something here, but attempting to run

from google_images_search import GoogleImagesSearch

gis = GoogleImagesSearch('omitted','omitted')
_search_params = {
    'q': 'dog',
    'num': 1,
    'safe': 'off'
}
gis.search(search_params=_search_params)

and am getting the following error

Traceback (most recent call last):
  File "/Users/calebcarithers/Desktop/Project_TBD/google_image_test.py", line 9, in <module>
    gis.search(search_params=_search_params)
  File "/Users/calebcarithers/Desktop/Project_TBD/venv/lib/python3.7/site-packages/google_images_search/fetch_resize_save.py", line 55, in search
    search_params, cache_discovery
  File "/Users/calebcarithers/Desktop/Project_TBD/venv/lib/python3.7/site-packages/google_images_search/google_api.py", line 79, in search
    for image in res.get('items'):
TypeError: 'NoneType' object is not iterable

Just a question

Hi

Does this code allow me to get the image url and the original url of the site the image is from to allow attribution.

Thanks

Time out

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?

ModuleNotFoundError: No module named '_curses' on Windows

Getting this error when running in windows:

C:\Users\anwar\Desktop\gitlab-helper\venv\Scripts\python.exe C:/Users/anwar/Desktop/gitlab-helper/project-avatar-updater.py
Traceback (most recent call last):
  File "C:/Users/anwar/Desktop/gitlab-helper/project-avatar-updater.py", line 1, in <module>
    from google_images_search import GoogleImagesSearch
  File "C:\Users\anwar\Desktop\gitlab-helper\venv\lib\site-packages\google_images_search\__init__.py", line 1, in <module>
    from google_images_search.fetch_resize_save import \
  File "C:\Users\anwar\Desktop\gitlab-helper\venv\lib\site-packages\google_images_search\fetch_resize_save.py", line 2, in <module>
    import curses
  File "C:\Python38\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ModuleNotFoundError: No module named '_curses'

Used the demo on readme

Query language.

It looks like I can only search using queries written in English, is that so? If it is, how to include an additional parameter in the search query to account for the query language? Thanks!

Update click to 7+

Hi Ivan, thank you for sharing your work!

Short question: May I ask you to update the dependency:

click==6.3

to

click~=7 ?

Couldn't download more than 1 image file

Code:

from google_images_search import GoogleImagesSearch

you can provide API key and CX using arguments,

or you can set environment variables: GCS_DEVELOPER_KEY, GCS_CX

def my_progressbar(url, progress):
print(str(url) + ' ' + str(progress) + '%')

gis = GoogleImagesSearch(API_key, CX_code, progressbar_fn=my_progressbar)

define search params:

_search_params = {
'q': 'dog',
'num': 10,
#'safe': 'high|medium|off',
#'fileType': 'jpg|gif|png',
#'imgType': 'clipart|face|lineart|news|photo',
#'imgSize': 'huge|icon|large|medium|small|xlarge|xxlarge',
#'imgDominantColor': 'black|blue|brown|gray|green|pink|purple|teal|white|yellow',
#'rights': 'cc_publicdomain|cc_attribute|cc_sharealike|cc_noncommercial|cc_nonderived'
}

my_bytes_io = BytesIO()

search first, then download and resize afterwards:

gis.search(search_params=_search_params, path_to_dir='./', width=500, height=500)

search first, then download and resize afterwards:

gis.search(search_params=_search_params)
for image in gis.results():
image.download('/path/')
image.resize(500, 500)

Execution log:

https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 1%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 2%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 3%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 4%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 5%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 6%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 7%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 8%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 9%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 10%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 11%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 12%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 13%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 14%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 15%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 16%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 17%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 18%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 19%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 20%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 21%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 22%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 23%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 24%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 25%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 26%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 27%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 28%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 29%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 30%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 31%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 32%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 33%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 34%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 35%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 36%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 37%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 38%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 39%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 40%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 41%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 42%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 43%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 44%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 45%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 46%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 47%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 48%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 49%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 50%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 51%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 52%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 53%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 54%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 55%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 56%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 57%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 58%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 59%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 60%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 61%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 62%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 63%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 64%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 65%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 66%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 67%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 68%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 69%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 70%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 71%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 72%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 73%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 74%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 75%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 76%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 77%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 78%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 79%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 80%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 81%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 82%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 83%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 84%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 85%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 86%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 87%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 88%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 89%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 90%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 91%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 92%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 93%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 94%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 95%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 96%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 97%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 98%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 99%
https://pyxis.nymag.com/v1/imgs/0c2/a83/4cfc644e76854d6cfe92f58219d2273a25-14-courage-the-cowardly-dog.rsquare.w1200.jpg 100%

Execution ends here

HTTP error during search

Hi there,

I am getting "HTTP error" during image search, it usually appears in the middle of the search process and it seems to be request specifications depended. API downloads some images and throws an error in the middle of the process. For example it throws an error for set of parameters:

_search_params = {
   'q': 'COVID-19',
   'num': 20,
   'safe': 'off',
   'fileType': 'jpg',
   'imgSize': 'MEDIUM',
}

Full error log:

HttpError                                 Traceback (most recent call last)
<ipython-input-4-f508988bf31b> in <module>
----> 1 gis.search(search_params=_search_params, path_to_dir='./Images_try/') #, path_to_dir='./Images_try/'

~/.conda/envs/tf2/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py in search(self, search_params, path_to_dir, width, height, custom_image_name, cache_discovery)
    119             self._search_params['num'] = num
    120 
--> 121             self._search_images(*self._get_data())
    122 
    123             if len(self._search_result) >= self._number_of_images or self.zero_return:

~/.conda/envs/tf2/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py in _search_images(self, search_params, path_to_dir, width, height, cache_discovery)
    144         i = 0
    145         threads = []
--> 146         for url in self._google_custom_search.search(
    147             search_params, cache_discovery
    148         ):

~/.conda/envs/tf2/lib/python3.8/site-packages/google_images_search/google_api.py in search(self, params, cache_discovery)
     76 
     77         search_params = self._search_params(params)
---> 78         res = self._query_google_api(search_params, cache_discovery)
     79 
     80         results = res.get('items', [])

~/.conda/envs/tf2/lib/python3.8/site-packages/google_images_search/google_api.py in _query_google_api(self, search_params, cache_discovery)
     44                                        cache_discovery=cache_discovery)
     45 
---> 46         return self._google_build.cse().list(
     47             cx=self._custom_search_cx, **search_params).execute()
     48 

~/.conda/envs/tf2/lib/python3.8/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

~/.conda/envs/tf2/lib/python3.8/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
    905             callback(resp)
    906         if resp.status >= 300:
--> 907             raise HttpError(resp, content, uri=self.uri)
    908         return self.postproc(resp, content)
    909 

HttpError: <HttpError 400 when requesting https://customsearch.googleapis.com/customsearch/v1?cx={my id}f&q=COVID-19&searchType=image&num=20&start=11&imgSize=MEDIUM&fileType=jpg&safe=off&key={my key}&alt=json returned "Request contains an invalid argument.">

Following the link doesn't help much, it says:

{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}

Looking for error causes in the Internet I found that people have similar problems with other Google APIs but their solutions didn't help.

I am using GIS version 1.3.3 and python version 3.8.3.

Thank you!

urllib3 warning : InsecureRequestWarning: Unverified HTTPS request

Hey,

First let me thank you for the very useful package ! I started using it recently and everything works fine, but I keep getting the following warning when running the search function:

"InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)"

Any idea where it comes from/ how to fix it ? Any help would be welcome !

Thanks again

jeremy

How to know the approximate time the photo was taken?

Hi Arrrlo,

Thank you for the code. I was able to successfully run the code.

After getting those images of a person, how to figure out the approximate time the photo was taken?

For instance, I get 10 images of Mark Zuckerberg. How do I tell that this was Mark Zuckerberg in 2010, that was Mark in 2011, etc.?

Thanks
Mike

'start' parameter seems to not working

I want to get the second result of a search without uselessly use my quota with "num" parameter (which using quickly my quota).

So I wanted to use 'start' parameter but it seems to not working, it returns me the same image each time.

What this code is doing ?
image

Why not using this ?
search_params.get('start') or start

Setting num as 10 returns more than 10 results

When using num as 10, it seems to produce more than this vale, running two iterations rather than 1 (as used for finding more than 10 results mentioned in readme)

({'q': 'dogs', 'num': 10, 'imgType': 'lineart', 'start': 11}, '/home/administrator/Pictures', None, None, False)
({'q': 'dogs', 'num': 10, 'imgType': 'lineart', 'start': 11}, '/home/administrator/Pictures', None, None, False)

pipeline '|' in search params not working

Following is my search param:

_search_params = {
            'q': 'puppy',
            'num': 5,
            'safe': 'high',
            'fileType': 'jpg|png|gif',
            'imgSize': 'huge|icon|large|medium|small|xlarge|xxlarge',
            'searchType': 'image',
            'imgDominantColor': 'black'
        }

Error:
TypeError: Parameter "imgSize" value "huge|icon|large|medium|small|xlarge|xxlarge" is not an allowed value in "['huge', 'icon', 'large', 'medium', 'small', 'xlarge', 'xxlarge']"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.