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

Always include "__Secure-1PSIDTS" to avoid the "SNlM0e value not found" error. #254

Closed
wants to merge 1 commit into from

Conversation

SetoKaiba
Copy link

@SetoKaiba SetoKaiba commented Dec 28, 2023

I welcome the overall code refactoring and new features. However, please make sure to conduct QA. Before making a PR, please check the entire functionality by adding it to https://github.com/dsdanielpark/Bard-API/blob/main/func_test.ipynb. Due to various reasons, I couldn't implement test mocking code. I also welcome anyone who can provide test mocking and refactoring. But please keep the existing method names and examples. While I aim to accept PRs as quickly as possible, they may be rejected if QA is not correct.

BARD-API Pull Request Template

Please provide the necessary information as succinctly as possible. I appreciate it if you write it in an easy-to-read format as I don't have much time to dedicate to maintaining this package.

Description

Always include __Secure-1PSIDTS to avoid the "SNlM0e value not found" error.

If it uses __Secure-1PSID only, it will soon meet the SNlM0e value not found.
If it uses __Secure-1PSID and __Secure-1PSIDTS together, it won't.

Related Issue

#155

Motivation and Context

#155
I meet the SNlM0e value not found just after a few minutes. The __Secure-1PSID is not changed yet in the browser. But the Bard-API reports the problem. I found that using __Secure-1PSID and __Secure-1PSIDTS together will avoid this problem.

And also, I found some limitation of browser_cookie3.
I have cookies for .google.com.hk. But it filter the cookies by like sql. So the .google.com.hk and .google.com cookies are both in the results. The .google.com.hk cookie will override the .google.com cookie. It may cause the Bard API use the wrong values from .google.com.hk.
The problem comes from browser_cookie3. So this problem I can't find a way to fix it unless I delete the .google.com.hk cookies.

How Has This Been Tested?

I tested the sync version. It's working.

But the async version is not tested.
Because I found some problem even with the orignal one.

Traceback (most recent call last):
  File "E:\PycharmProjects\testGemini\test2.py", line 12, in <module>
    bard = BardAsync(token_from_browser=True, conversation_id='c_b3c979de2d5c535d')
  File "E:\PycharmProjects\testGemini\.venv\lib\site-packages\bardapi\core_async.py", line 80, in __init__
    self.SNlM0e = self._get_snim0e()
  File "E:\PycharmProjects\testGemini\.venv\lib\site-packages\bardapi\core_async.py", line 106, in _get_snim0e
    resp = self.client.get(
AttributeError: 'coroutine' object has no attribute 'get'
sys:1: RuntimeWarning: coroutine 'BardAsync._get_client' was never awaited

Thank you once again to all the contributors. Your efforts are greatly appreciated!

@SetoKaiba
Copy link
Author

SetoKaiba commented Dec 31, 2023

It seems that it doesn't need the whole cookies. But it always needs __Secure-1PSID, __Secure-1PSIDCC and __Secure-1PSIDTS.
The reference repo always includes __Secure_1PSIDTS as well.
https://github.com/acheong08/Bard
I'll modify the PR.

@SetoKaiba SetoKaiba changed the title Use the whole cookies to avoid the "SNlM0e value not found" error. Always include "__Secure-1PSIDTS" to avoid the "SNlM0e value not found" error. Dec 31, 2023
Copy link

gitguardian bot commented Dec 31, 2023

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
- Google Bard API Key b1aa195 func_test.ipynb View secret
- Generic High Entropy Secret b1aa195 bardapi/core_async.py View secret
- Generic High Entropy Secret b1aa195 bardapi/core_async.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@dsdanielpark
Copy link
Owner

https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard

Hello. Thank you very much for your wonderful contribution.

Regarding the cookie values, I have confirmed that in some regions, it is necessary to use two or three or more cookies. This has been addressed through Multi-cookies Bard. (Especially, users in China and Japan have reported this)

Generally, in most regions, accounts, and countries, a single cookie value is sufficient for a normal response, so I need to be a bit more cautious in accepting this PR. (The current code enforces the use of two cookie values)

Therefore, I will give this PR further consideration.

Thank you for your ideas and work.

@SetoKaiba
Copy link
Author

SetoKaiba commented Jan 2, 2024

https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard

Hello. Thank you very much for your wonderful contribution.

Regarding the cookie values, I have confirmed that in some regions, it is necessary to use two or three or more cookies. This has been addressed through Multi-cookies Bard. (Especially, users in China and Japan have reported this)

Generally, in most regions, accounts, and countries, a single cookie value is sufficient for a normal response, so I need to be a bit more cautious in accepting this PR. (The current code enforces the use of two cookie values)

Therefore, I will give this PR further consideration.

Thank you for your ideas and work.

OK. Then, for token from browser, I think that it should get the 3 cookies if it exists, not just __Secure-1PSID.

@dsdanielpark
Copy link
Owner

Thank you once again for your feedback. I will check to ensure that auto cookies can refresh three cookies. Also, please reconfirm if the issue you raised cannot be solved with multi-cookie bard as described here:

https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard

As shown in the example, assigning three cookies to a session object and passing it to bard should make it possible to use the Bard class with the intended functionality of using three cookie values.

Looking forward to your feedback. Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants