Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__Secure-1PSIDTS #6

Closed
raymerjacque opened this issue Feb 25, 2024 · 9 comments
Closed

__Secure-1PSIDTS #6

raymerjacque opened this issue Feb 25, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@raymerjacque
Copy link

raymerjacque commented Feb 25, 2024

the __Secure-1PSIDTS expires very quickly... is there no way around this ? a script to renew it, or another method of authentication ? another cookie or token that can be used ?

some google account dont even show "__Secure-1PSIDTS" its not available in F12 or cookie editor, what to do in such cases ?

@HanaokaYuzu
Copy link
Owner

As mentioned in readme, the best workaround is to use a separate google account.

Note: `__Secure-1PSIDTS` could get expired frequently if the Google account is actively used elsewhere, especially when visiting <https://gemini.google.com> directly. It's recommended to use a separate Google account if you are builing a keep-alive service with this package.

@HanaokaYuzu
Copy link
Owner

If there's no "__Secure-1PSIDTS" in your account's cookie list, simply leaving it empty should work. (I believe so, if not just let me know :)

@raymerjacque
Copy link
Author

no, leaving the field blank just gives me :

File "/usr/local/lib/python3.10/dist-packages/gemini/client.py", line 124, in init
raise AuthError(
gemini.types.AuthError: Failed to initiate client. SECURE_1PSIDTS could get expired frequently, please make sure cookie values are up to date.

ERROR: Application startup failed. Exiting.

@HanaokaYuzu HanaokaYuzu reopened this Feb 25, 2024
@HanaokaYuzu

This comment was marked as outdated.

@HanaokaYuzu HanaokaYuzu added the bug Something isn't working label Feb 26, 2024
@satounity
Copy link

satounity commented Feb 26, 2024

This is a translation, so please excuse my poor English.

I was also bothered by the early deadline.
It expired in about 5-10 minutes.

However, if you close Gemini's screen immediately after retrieving the cookie, the cookie can be used for a long time.
In fact, I have been using it continuously for over a week.

As a procedure
There is no "__Secure-1PSIDTS" after Gemini re-login.
After a while, "__Secure-1PSIDTS" will appear.
(I don't know the conditions under which "__Secure-1PSIDTS" appears, but...)

After getting the values of “__Secure-1PSID” and “__Secure-1PSIDTS”
Close the Gemini screen.
If the Gemini screen is left open, cookies in Python will expire quickly.

@HanaokaYuzu
Copy link
Owner

However, if you close Gemini's screen immediately after retrieving the cookie, the cookie can be used for a long time.

You are right. Combined with another separate account it can last even longer (in my own case around 1 month)

As a procedure There is no "__Secure-1PSIDTS" after Gemini re-login. After a while, "__Secure-1PSIDTS" will appear.

I believe this behavior can be different by account. My account has __Secure-1PSIDTS immediately after logging out and re-login.

Btw re-login will force refresh your previous __Secure-1PSID and __Secure-1PSIDTS.

@HanaokaYuzu HanaokaYuzu added the help wanted Extra attention is needed label Feb 28, 2024
@HanaokaYuzu
Copy link
Owner

@raymerjacque Can you update to the latest version can try again with the account without __Secure-1PSIDTS?

@Ran-Mewo
Copy link

Ran-Mewo commented Mar 3, 2024

what I did was go into an incognito tab, login to gemini from there and use those cookies
it's been quite a long time and it still hasn't expired for me

@HanaokaYuzu HanaokaYuzu pinned this issue Mar 3, 2024
HanaokaYuzu added a commit that referenced this issue Mar 19, 2024
- feat: add support to auto refresh cookies in background
- feat: add support to import cookies from local browser
- feat: add support to control log level
- feat: now client will automatically retry when generate_content raises APIError
- fix: now the timeout value will be correctly applied after re-initializing the client
- docs: update readme and function docstrings
- refactor: split utils.py into multiple files
- build: update supported python version

close #6
@iamyifan
Copy link

iamyifan commented Mar 23, 2024

Hey, I had the same issue before.

My solution is that (macOS + Chrome):

  1. Open an incognito tab.
  2. Type Fn-12, and check out the network tab.
  3. Cope the __Secure-1PSID and __Secure-1PSIDTS to the right place. According to other people, __Secure-1PSIDTS may be missing in your cookies, but only using __Secure-1PSID works for me.
    Your code should look like this:
import asyncio
from gemini_webapi import GeminiClient

# Replace "COOKIE VALUE HERE" with your actual cookie values.
# Leave Secure_1PSIDTS empty if it's not available for your account.

# chop off the "__Secure_1PSID=" and ";" at the end
Secure_1PSID = 'g.a0_something_something_076'
# chop off the "__Secure_1PSIDTS=" and ";" at the end
Secure_1PSIDTS = 'sidts-somgthing_somgthing_EAA'

async def main():
    # If browser-cookie3 is installed, simply use `client = GeminiClient()`
    client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxies=None)
    await client.init(timeout=30, auto_close=False, close_delay=300, auto_refresh=False)  # I turned auto-refresh off

asyncio.run(main())
  1. Haven't tested how long it can stay connected but It should work fine now : )

@HanaokaYuzu HanaokaYuzu removed the help wanted Extra attention is needed label Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants