dsdanielpark / Bard-API

The unofficial python package that returns response of Google Bard through cookie value.
https://pypi.org/project/bardapi/
MIT License
5.34k stars 531 forks source link

TooManyRedirects: Exceeded 30 redirects. #281

Closed Walkercito closed 5 months ago

Walkercito commented 6 months ago

I was testing the library in a Discord bot, I'm sure I did it right but for some reason it says that I exceeded 30 redirects when the bot just started, the error poped up.

Version OS: Windows Python: Python 3.12 Using proxy: No

Code

import discord
from bardapi import Bard
from discord.ext import commands

class Response(commands.Cog):
    def __init__(self, bot) -> None:
        self.bot = bot
        self.TOKEN = "xxxxxxxxx"

        self.api = Bard(self.TOKEN)

    @commands.Cog.listener()
    async def on_message(self, message: discord.Message):
        if message.author == self.bot.user:
            return

        if "gato" in message.content.lower():
            content = message.content

            async with message.channel.typing():
                try:
                    response = self.api.get_answer(content)['content']
                    await message.channel.send(response)

                except Exception as e:
                    print(e)
                    await message.channel.send(f"Error: {e}")

async def setup(bot):
    await bot.add_cog(Response(bot))

Error

2024-02-17 06:30:42 ERROR    discord.client Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 947, in _load_from_module_spec
    await setup(self)
  File "/workspaces/MrGato/cogs/response.py", line 33, in setup
    await bot.add_cog(Response(bot))
  File "/workspaces/MrGato/cogs/response.py", line 12, in __init__
    self.api = Bard(self.TOKEN)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/bardapi/core.py", line 80, in __init__
    self.SNlM0e = self._get_snim0e()
  File "/home/codespace/.python/current/lib/python3.10/site-packages/bardapi/core.py", line 151, in _get_snim0e
    resp = self.session.get(
  File "/home/codespace/.local/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/home/codespace/.local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/codespace/.local/lib/python3.10/site-packages/requests/sessions.py", line 725, in send
    history = [resp for resp in gen]
  File "/home/codespace/.local/lib/python3.10/site-packages/requests/sessions.py", line 725, in <listcomp>
    history = [resp for resp in gen]
  File "/home/codespace/.local/lib/python3.10/site-packages/requests/sessions.py", line 191, in resolve_redirects
    raise TooManyRedirects(
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "/workspaces/MrGato/main.py", line 15, in on_ready
    await bot.load_extension(f"cogs.{cog_file.name[:-3]}")
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1013, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 952, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.response' raised an error: TooManyRedirects: Exceeded 30 redirects.
dsdanielpark commented 5 months ago

[NOTICE] Please, go to Gemini-API https://github.com/dsdanielpark/Gemini-API

PyPI

Gemini Icon Google - Gemini API

A unofficial Python wrapper, python-gemini-api, operates through reverse-engineering, utilizing cookie values to interact with Google Gemini for users struggling with frequent authentication problems or unable to authenticate via Google Authentication.

Collaborated competently with Antonio Cheong.

What is Gemini?

[Paper] [Official Website] [Official API] [API Documents]

Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro and Gemini Pro Vision models. In February 2024, Google's Bard service was changed to Gemini.


Installation

pip install python-gemini-api
pip install git+https://github.com/dsdanielpark/Gemini-API.git

For the updated version, use as follows:

pip install -q -U python-gemini-api