Hello, this program has been incredibly useful, but I've gotten stuck while trying to download a single image in a Python script. I'm still relatively new to Python and these programs so forgive me if it's a silly question. The command (below) seems to ignore the single image argument entirely and simply proceed to download 100 images using the keywords. Having the keywords argument seems unnecessary to download an image from an url, but I get an error if the argument is not included (UnboundLocalError: local variable 'search_keyword' referenced before assignment).
from google_images_download import google_images_download
response = google_images_download.googleimagesdownload()
image_url = 'https://upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'
response.download({"keywords":"jack russel terrier", "single_image": image_url})
To debug, I attempted to implement the example from the documentation. Although I am using a Python script, only a command line example is available using the single_image argument
googleimagesdownload --keywords "baloons" --single_image <URL of the images>
To which I get the following errors:
(base) C:\Users\Eugene>googleimagesdownload --keywords "jack russel" --single_image 'https://upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'
Traceback (most recent call last):
File "c:\users\eugene\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\eugene\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Eugene\anaconda3\Scripts\googleimagesdownload.exe\__main__.py", line 7, in <module>
File "c:\users\eugene\anaconda3\lib\site-packages\google_images_download\google_images_download.py", line 1134, in main
response.single_image(arguments['single_image'])
File "c:\users\eugene\anaconda3\lib\site-packages\google_images_download\google_images_download.py", line 416, in single_image
response = urlopen(req, None, 10)
File "c:\users\eugene\anaconda3\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "c:\users\eugene\anaconda3\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "c:\users\eugene\anaconda3\lib\urllib\request.py", line 548, in _open
'unknown_open', req)
File "c:\users\eugene\anaconda3\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "c:\users\eugene\anaconda3\lib\urllib\request.py", line 1389, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: 'https>
Since there seems to be some issues with the url, I tried some variants:
(base) C:\Users\Eugene>googleimagesdownload --keywords "jack russel" --single_image 'upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'
...
ValueError: unknown url type: "'upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'"
(base) C:\Users\Eugene>googleimagesdownload --keywords "jack russel" --single_image 'https://upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'
...
urllib.error.URLError: <urlopen error unknown url type: 'https>
I checked the requests module in Python, and it seems to be working:
import requests
image_url = 'https://upload.wikimedia.org/wikipedia/commons/f/f1/Jack_Russell_Terrier_1.jpg'
r = requests.get(image_url, allow_redirects=True)
So I'll just be using this as a substitute, but would be great to use the google_images_download program feature.
Hello, this program has been incredibly useful, but I've gotten stuck while trying to download a single image in a Python script. I'm still relatively new to Python and these programs so forgive me if it's a silly question. The command (below) seems to ignore the single image argument entirely and simply proceed to download 100 images using the keywords. Having the keywords argument seems unnecessary to download an image from an url, but I get an error if the argument is not included (UnboundLocalError: local variable 'search_keyword' referenced before assignment).
To debug, I attempted to implement the example from the documentation. Although I am using a Python script, only a command line example is available using the single_image argument
googleimagesdownload --keywords "baloons" --single_image <URL of the images>To which I get the following errors:
Since there seems to be some issues with the url, I tried some variants:
I checked the requests module in Python, and it seems to be working:
So I'll just be using this as a substitute, but would be great to use the google_images_download program feature.