Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Add auto rotation cookies #191

Closed
Mrgaton opened this issue Sep 27, 2023 · 11 comments
Closed

Add auto rotation cookies #191

Mrgaton opened this issue Sep 27, 2023 · 11 comments
Labels
inprocessing I'm in the process of fixing the code.

Comments

@Mrgaton
Copy link

Mrgaton commented Sep 27, 2023

Any system to be able to auto-generate the bard cookies automatically with the Google session to be able to make the system completely autonomous

@Zyx0r
Copy link

Zyx0r commented Oct 17, 2023

I used browser_cookie3, I go to read the Google Chrome cookies that I opened previously, and then I can make all the calls I want without having to manually update the values.

if it gives you the permission denied error, the shortcut to the chrome executable should be modified by adding --disable-features=LockProfileCookieDatabase

 import browser_cookie3
 
 def find_cookie(cookie, field):
     for i in cookie:
         if(i.name == field):
             return i.value
 
 session = requests.Session()
 cookies = browser_cookie3.chrome(domain_name='.google.com')
 PPSID = find_cookie(cookies, '__Secure-1PSID')
 DCC = find_cookie(cookies, '__Secure-1PSIDCC')
 DTS = find_cookie(cookies, '__Secure-1PSIDTS')
 token = PPSID
 session.cookies.set("__Secure-1PSID", PPSID)
 session.cookies.set( "__Secure-1PSIDCC", DCC)
 session.cookies.set("__Secure-1PSIDTS", DTS)
 session.headers = SESSION_HEADERS

@marco99asr
Copy link

does it work? After more time unused tokens still works ?

@marco99asr
Copy link

if it works;
@dsdanielpark can be an enhancement?

@dsdanielpark dsdanielpark added the inprocessing I'm in the process of fixing the code. label Nov 14, 2023
@dsdanielpark
Copy link
Owner

dsdanielpark commented Nov 14, 2023

marco99asr
I am currently working on multiple projects, so I will conduct feature testing as time allows this weekend and proceed with updates as necessary. I appreciate the issue creation and information from Zyx0r, szv99.

Also, anyone can contribute by making modifications and creating a Pull Request without having to wait.

We always look forward to active communication and your opinions.
Thank you.

@marco99asr
Copy link

we have to understand how client refresh tokens when they expire.
I tryed rotation of cookies but in sessions they didn't change.
Client maybe refresh token with an api but what kind of api?

@marco99asr
Copy link

marco99asr commented Nov 14, 2023

using this i never saw change cookies....
my code:


def saveCookiesNull():
printLog("saveCookiesNull()")
cookies = {
"__Secure-1PSID" : "",
"__Secure-1PSIDCC" : "",
"__Secure-1PSIDTS" : ""
}
with open("bardCookies.json", "w") as f:
json.dump(cookies, f)


def loadCookie(cookie):
printLog("loadCookie(cookie)")
try:
with open("bardCookies.json", "r") as f:
return json.load(f)[cookie]
except FileNotFoundError:
saveCookiesNull()
return loadCookie(cookie)


def saveCookies(cookie, value):
printLog("saveCookies(cookie, value)")
cookies = {}
try:
with open("bardCookies.json", "r") as f:
cookies = json.load(f)
except FileNotFoundError:
saveCookiesNull()
cookies[cookie] = value
with open("bardCookies.json", "w") as ff:
json.dump(cookies, ff)


def find_cookie(cookie, field, check):
printLog("find_cookie(cookie, field)")
for i in cookie:
if(i.name == field):
if i.value != check:
printLog(field + " is different")
return i.value

---------------------main------------------------------------
PPSID = loadCookie("__Secure-1PSID")
DCC = loadCookie( "__Secure-1PSIDCC")
DTS = loadCookie("__Secure-1PSIDTS")

session = requests.Session()
session.cookies.set("__Secure-1PSID", PPSID)
session.cookies.set( "__Secure-1PSIDCC", DCC)
session.cookies.set("__Secure-1PSIDTS", DTS)

printLog(session.cookies)
session.headers = SESSION_HEADERS
bard = Bard(token=PPSID, session=session)
input_text = ""

response = bard.get_answer(input_text)

PPSID = find_cookie(session.cookies, '__Secure-1PSID', PPSID)
DCC = find_cookie(session.cookies, '__Secure-1PSIDCC', DCC)
DTS = find_cookie(session.cookies, '__Secure-1PSIDTS', DTS)
session.cookies.set("__Secure-1PSID", PPSID)
session.cookies.set( "__Secure-1PSIDCC", DCC)
session.cookies.set("__Secure-1PSIDTS", DTS)

saveCookies("__Secure-1PSID", PPSID)
saveCookies( "__Secure-1PSIDCC", DCC)
saveCookies("__Secure-1PSIDTS", DTS)

@marco99asr
Copy link

sad story im blocked by bard server:

2023-11-14 22:18:25,276 - DEBUG - https://bard.google.com:443 "GET / HTTP/1.1" 302 363
2023-11-14 22:18:25,564 - DEBUG - https://www.google.com:443 "GET /sorry/index?continue=https://bard.google.com/&q=EgSetOVNGLHkz6oGIjC__cLZI-D9CD0K9rTVy1nhmdP3S94HYepCY_nv2pRabRvl5uKAO-EMSrwn6mnXGo0yAXJaAUM HTTP/1.1" 429 3091
2023-11-14 22:18:25,565 - DEBUG - Bard Error!

@dsdanielpark
Copy link
Owner

marco99asr

  1. Based on these two points, you may have received an HTTP 429 error. If it is determined that the requests are not from a person but from a macro or a repetitive loop, your account may be temporarily or permanently blocked.

    • Do not send requests too frequently.
    • Do not repeatedly send the same question.
  2. Consider logging out from the browser and completely closing all browsers before starting again for token refresh. Alternatively, refer to the method of resetting cookies in each browser.

The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time (rate limiting).

@dsdanielpark
Copy link
Owner

dsdanielpark commented Dec 1, 2023

Please refer to pull request #235 by szv99.

We are currently working on it, and if possible, I plan to proceed with the update by the end of December.

If the update is stable, I will release it as version 0.1.39.

@Billy19191
Copy link

Please refer to pull request #235 by szv99.

We are currently working on it, and if possible, I plan to proceed with the update by the end of December.

If the update is stable, I will release it as version 0.1.39.

That would be awesome! Cheer

@dsdanielpark
Copy link
Owner

[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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
inprocessing I'm in the process of fixing the code.
Projects
None yet
Development

No branches or pull requests

5 participants