Giter Site home page Giter Site logo

Comments (2)

JacobCll avatar JacobCll commented on July 18, 2024

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.

arrrlo avatar arrrlo commented on July 18, 2024

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)

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.