dsdanielpark / Bard-API

The unofficial python package that returns response of Google Bard through cookie value.

Home Page:https://pypi.org/project/bardapi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple-Cookies has been changed.

mathisen99 opened this issue · comments

Hello!
it seem google have changed this again. now the value dont end with an . anymore.
i have looked at older issues, i did try to use version 0.1.39 but no go. the as it seem to expect the value to end with an . as i am getting this error with it

__Secure-1PSID value should end with a single dot. Enter correct __Secure-1PSID value.

My region EU / scandinavia

I also did have an open old session in another browser that still used the older value that ended with dot, but that stoped working today.

is there any fix for this ?

New value looks like this:

g.a000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0076

also when i looked at the Multi-cookie Bard example, one of the values does not exist anymore "__Secure-1PSIDTS".
These are the new values:
values

Same problem, no longer able to generate responses even after updating to bardapi==0.1.39

@dsdanielpark Yes i looked into that, but the code example want the second cookie to be " __Secure-1PSIDTS " value but that cookie does not exist anymore.
If you look at the image i have attached to the main issue that is all cookies that exists now.

mathisen99
Some users have reported that the cookie value does not end with a single dot, but there have been no additional issues.

Firstly, try experimenting with different cookie values to find a method that works correctly. Alternatively, you could use a VPN to bypass and set it to a different country or region, or try changing the nationality of the google account. Recently, Google seems to be taking a tough stance on bypassing with VPNs or changing countries, especially regarding YouTube Premium or other Google Cloud Services.

I apologize for the difficulty in debugging or finding a solution directly, as I cannot reproduce the error myself.

Unfortunately, there are no other ways I can help, except for developers facing similar challenges to find and share workarounds. As mentioned in the FAQ or README, sadly, the Bard-API package is an unofficial package and may become unusable at any time.

I will keep this issue open. Thank you.

same problem, IP from Ukraine, Bard 0.1.38, but doesn’t work with 0.1.39 either, the cookie file requires it to end with .

OlegRuban-ai

The message stating that it should end with a single dot in 0.1.39 version is merely a print statement for testing purposes, not an asset. You should pay attention to the next error message following this statement.

@dsdanielpark

thanks, it worked. For some reason it works in combination with __Secure-ENID, I continue testing

OlegRuban-ai
What a nice.

I hope you find it! Please share with the other users.

@dsdanielpark
Hi, I noticed that all the same cookies are needed to work (__Secure-1 PSID and __Secure-1PSIDTS). If you log in separately via selenium using these cookies, everything will work fine

@SPomodor please provide a more explantion..it will be very valuaeable.

New documentation have been made for new args.

After patching the library by removing the check if the __Secure-1PSID cookie ends with a dot in bardapi/core.py (line 173) and bardapi/utils.py (line 106) the following code works for me (with firefox as browser)

from bardapi import Bard

bard = Bard(token_from_browser=True, multi_cookies_bool=True)
bard.get_answer("What is Bard?")

it is working..But how to use bard api on a linux server having no web browser ..maybe i sounds stupid.

I have found the solution for this.

But I think this only works with Firefox browser.

Here are the steps to use the latest Gemini AI through Bardapi with some kind of stability.

Install Firefox.

Sign in to Gemini (formerly Bard) with your google account credentials.

Unzip the updated files which are attached here and place it in the appropriate folders

Then you will be able to use bardapi seamlessly with the following code. Every time you run this code, it will extract the new cookies from firefox and send it to bardapi.
Make sure to pip install browser_cookie3.

import requests
from bardapi import SESSION_HEADERS, BardCookies
import browser_cookie3

domain = '.google.com'

firefox_cookies = browser_cookie3.firefox(domain_name=domain)

psid = '__Secure-1PSID'
dts = '__Secure-1PSIDTS'
dcc = '__Secure-1PSIDCC'
nid = 'NID'

psid_value = None
dts_value = None
dcc_value = None
nid_value = None

for cookie in firefox_cookies:
    if cookie.name == psid:
        psid_value = cookie.value
    elif cookie.name == dts:
        dts_value = cookie.value
    elif cookie.name == dcc:
        dcc_value = cookie.value
    elif cookie.name == nid:
        nid_value = cookie.value


cookie_dict = {
    "__Secure-1PSID": psid_value,
    "__Secure-1PSIDTS": dts_value,
    "__Secure-1PSIDCC": dcc_value,
}
session = requests.Session()
session.cookies.set("__Secure-1PSID", psid_value)
session.cookies.set( "__Secure-1PSIDCC", dcc_value)
session.cookies.set("__Secure-1PSIDTS", dts_value)
session.cookies.set("NID",nid_value)
session.headers = SESSION_HEADERS

bard = BardCookies(session=session,cookie_dict=cookie_dict)

while True:

    question = input("Enter your prompt to Gemini: ")
    response = bard.get_answer(question)['content']
    data = str(response).replace("*", "")
    print(data)
    

Updated files.zip

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

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