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

gemini_webapi.GeminiClient() not able to retrieve cookies #33

Closed
a-sajjad72 opened this issue Aug 18, 2024 · 4 comments
Closed

gemini_webapi.GeminiClient() not able to retrieve cookies #33

a-sajjad72 opened this issue Aug 18, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@a-sajjad72
Copy link

a-sajjad72 commented Aug 18, 2024

I am experiencing issues while initiating a connection to Gemini using GeminiClient(). I had tried it on two machines with two different browsers.

  1. Ubuntu 24.04 with Mozilla Firefox
  2. Windows 10 22H2 with Edge

It gives error of ValueError: Failed to load cookies from local browser. Please pass cookie values manually. By passing the values manually it works like a charm.

I am not sure whether I post this issue here or on browser-cookie3 repo. I will give you more details if you need any information to resolve this issue. Thank You 😃

Warm Regards,
Sajjad Ali

Traceback

2024-08-18 13:11:50.070 | WARNING  | gemini_webapi.utils.load_browser_cookies:load_browser_cookies:44 - Permission denied while trying to load cookies from edge. [Errno 13] Permission denied: 'C:\\Users\\asajj\\AppData\\Roaming\\..\\Local\\Microsoft\\Edge\\User Data\\Default\\Network\\Cookies'Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\testing.py", line 22, in <module>
    asyncio.run(main())
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\testing.py", line 15, in main
    client = GeminiClient()
             ^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 131, in __init__
    raise ValueError(
ValueError: Failed to load cookies from local browser. Please pass cookie values manually.
@a-sajjad72
Copy link
Author

a-sajjad72 commented Aug 18, 2024

My bad, I oversighted the Warning which shows PermissionError. This is due to the LockProfileCookieDatabase feature in Chromium based browsers. The work around is to close the browser then run it will work fine. But need to close the running browser everytime when the program should be run.
What would I suggest to save the cookies values in a file so that it can be used for the next time without retrieving them from the browser.

EDIT: I tired it but this issue occurs gemini_webapi.exceptions.AuthError: Failed to initialize client. SECURE_1PSIDTS could get expired frequently, please make sure cookie values are up to date. The below-mentioned is only the automated way I guess.

@HanaokaYuzu What do you think about the shadowcopy as discussed here? There is also PR for that but not pushed yet.

@HanaokaYuzu
Copy link
Owner

Actually the current mechanism does exactly what you suggested: when client is successfully initialized, the valid cookie value will be stored to a local file and keeps updating in background when client is running. Later every time the client tries to initialize, the stored cookie will be used even if browser_cookie3 raises an error.

If your client initialized successfully but browser_cookie3 raised an error, it shouldn't affect the client's functionality and can be ignored (or even uninstalled)

@HanaokaYuzu HanaokaYuzu added the enhancement New feature or request label Aug 30, 2024
@a-sajjad72
Copy link
Author

Actually the current mechanism does exactly what you suggested: when client is successfully initialized, the valid cookie value will be stored to a local file and keeps updating in background when client is running. Later every time the client tries to initialize, the stored cookie will be used even if browser_cookie3 raises an error.

If your client initialized successfully but browser_cookie3 raised an error, it shouldn't affect the client's functionality and can be ignored (or even uninstalled)

but the client not inialize when the chromium browsers are running. it failed to get the cookie files. the client only successfully initialized when the browser is closed successfully. This behaviour is happened when gemini_webapi.GeminiClient() used instead of providing cookie values manually.

HanaokaYuzu added a commit that referenced this issue Sep 11, 2024
@HanaokaYuzu
Copy link
Owner

Implemented an enhancement in v1.6.1. Now after a successful initialization, GeminiClient() should automatically use cached cookies regardless of whether cookie values are passed manually. Note that you may still need to quit browser for the first time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants