Comments (2)
Had the same issue in repl.it for a discord bot. Command runs fine in Vscode, but not there.
Code:
@bot.command()
async def img(ctx, *, args):
gis = GoogleImagesSearch(GOOGLE_API_KEY, CXID)
_search_params = {
'q': args,
'num': 3
}
gis.search(search_params=_search_params)
image_list = []
async with ctx.typing():
for image in gis.results():
image_list.append(image.url)
print(image_list)
await ctx.send(image_list[random.randint(0, len(image_list)-1)])
Error:
Ignoring exception in command img:
Traceback (most recent call last):
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 184, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 96, in img
gis.search(search_params=_search_params)
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/google_images_search/fetch_resize_save.py", line 151, in search
self._search_images(*self._get_data())
File "/home/runner/DiscordBot/venv/lib/python3.8/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 "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/google_images_search/google_api.py", line 83, in search
res = self._query_google_api(search_params, cache_discovery)
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/google_images_search/google_api.py", line 43, in _query_google_api
self._google_build = discovery.build(
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/googleapiclient/discovery.py", line 287, in build
content = _retrieve_discovery_doc(
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/googleapiclient/discovery.py", line 404, in _retrieve_discovery_doc
raise UnknownApiNameOrVersion(
googleapiclient.errors.UnknownApiNameOrVersion: name: customsearch version: v1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 342, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 951, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/DiscordBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 193, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnknownApiNameOrVersion: name: customsearch version: v1
from google-images-search.
Looks like sometimes Google API has problems with API discovery doc:
googleworkspace/python-samples#194
https://stackoverflow.com/questions/66700249/google-gmail-api-works-fine-as-py-but-throws-googleapiclient-errors-unknownap
This could be due to the google's dependency libs or something else.
Try to play with cache_discovery
argument when conducting the search:
gis = GoogleImagesSearch(GOOGLE_API_KEY, CXID)
_search_params = {...}
gis.search(search_params=_search_params, cache_discovery=True)
# the default is False
from google-images-search.
Related Issues (20)
- No Results HOT 3
- custom_image_name parameter doesn't work HOT 1
- "Request contains an invalid argument." when try to download a big number of images HOT 1
- Request to bump "google-api-python-client" dependency to 2.x HOT 1
- Search randomly fails with Http error. HOT 10
- No Images Found when using gimages search only HOT 2
- Can't specify image name using image.download HOT 1
- Understanding quotas HOT 1
- TypeError: Parameter HOT 1
- Please relax click version requirement, module works fine with 8.1.3 HOT 1
- Search parameters not being updated HOT 1
- Please add all other params like gl, cr, etc. HOT 1
- Add cache_discovery argument to docs/readme
- cache_discovery=False intermittently still returns cache images
- Option to use the Site Restricted API
- Custom search engine don't allow more the 100 results (start + num <= 100) per request
- Not getting correct results HOT 2
- HttpError with no particular message HOT 2
- gis.search() runs forever without any results or errors HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-images-search.