arrrlo / google-images-search Goto Github PK
View Code? Open in Web Editor NEW[PYTHON] Search for image using Google Custom Search API and resize & crop afterwards
License: MIT License
[PYTHON] Search for image using Google Custom Search API and resize & crop afterwards
License: MIT License
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?
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?
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 !
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
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
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?
Hello,
I also get a similar error when trying the below in CLI:
gimages search -q puppie
Thank you for your help.
Regards,
Laszlo Turi
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'
Is there any specific format for the q param ?
If I had several words like 'gartner magic quadrant
', I end up with no results, which is weird as doing the same test with the API trial of https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list provides the good results.
Please note that I used the CLI:
gimages search -q 'gartner magic quadrant' -n 10
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).
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 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
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.
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
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!
It would be very useful to have a option to set filename for downloaded image.
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
After the SSLError it continues to save files with a custom image name
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.
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.
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
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?
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. 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.
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']"
Thank You
Albertus Geyser
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?
The code does not know how to handle URLs starting with x-raw-image://, which sometimes appear in the output.
The error of the reguest module is thrown: No connection adapters were found for 'x-raw-image:
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
Running a fresh install from pip results in this error from one of the dependencies.
In the README,
Visit https://cse.google.com/cse/all and in the web form where you create/edit your custom search engine enable "Image search" option and for "Sites to search" option select "Search the entire web but emphasize included sites".
When I visit https://cse.google.com/cse/all, I get this page.
I clicked Add, then I get this. But it is not as you described in the README. What do I need to do?
Thanks.
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
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?
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
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!
Hi Ivan, thank you for sharing your work!
Short question: May I ask you to update the dependency:
click==6.3
to
click~=7 ?
Code:
from google_images_search import GoogleImagesSearch
def my_progressbar(url, progress):
print(str(url) + ' ' + str(progress) + '%')
gis = GoogleImagesSearch(API_key, CX_code, progressbar_fn=my_progressbar)
_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()
gis.search(search_params=_search_params, path_to_dir='./', width=500, height=500)
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
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!
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
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
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.
Why not using this ?
search_params.get('start') or start
I can download files, but I am wondering if I can extract the file url link from gis.search().
Is it possible?
Thanks.
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)
Hello, the code works with me, but the problem is that the retrieved images are different from google image search top results. sometimes the code returns irrelevant images
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']"
This is tool is really great with its inbuilt URL verification however it means many results are skipped. For example, I just did q:"dogs", num:"20"
and only got 8 results seeing that you have just added automatic pagination is it possible to extend this to attempt to get the num amount of verified images?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.