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

Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'. #155

Closed
Bharat9114 opened this issue Aug 7, 2023 · 58 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@Bharat9114
Copy link

Please make sure to check for more efficient package management. *Please prioritize checking existing issues first. *

@dsdanielpark I tried every ways possible but getting a exception: Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'.

i checked the 1PSID value, I tried with other account, cleared browser and cookies .
Earlier this was working well but from 16 days its showing same error.

Please Try to solve this problem.

@insafm
Copy link

insafm commented Aug 7, 2023

bard = Bard(token=token)

  File "/usr/local/lib/python3.10/site-packages/bardapi/core.py", line 67, in __init__
    self.SNlM0e = self._get_snim0e()
  File "/usr/local/lib/python3.10/site-packages/bardapi/core.py", line 564, in _get_snim0e
    raise Exception(
Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'.

@dsdanielpark
Copy link
Owner

dsdanielpark commented Aug 8, 2023

It may seem like I'm giving a repetitive answer, but this is not an issue that can be resolved externally.

I have checked that the functionality of the Bard API is working properly.

Please check if there have been any account locks or policy changes from Google for your Google account or in your region.

Since the error is not reproducible and it is likely related to policies within Google's internal API interface, I cannot assist further. Please consider sharing information with others who might be experiencing similar issues.

Furthermore, as this appears to be a duplicate issue #99

@Yorddyyorddy
Copy link

Yorddyyorddy commented Aug 9, 2023

i have faced the same issue it happens when the cookie value(email acc) used too many times and can be resolved by using all additional cookie values (I noticed this after inspecting the bard chat)

@JVTEAM
Copy link

JVTEAM commented Aug 9, 2023

recently attempted to fix this after index out of range error. Now I'm getting this error.

@Yorddyyorddy
Copy link

recently attempted to fix this after index out of range error. Now I'm getting this error.

use another email it can be resolved

@Dima-369
Copy link

I was able to solve it by wiping all cookies for https://bard.google.com in Firefox in the Developer Tools, logged back in with my same account. Then I noticed that the __Secure-1PSID cookie was renewed, so I used that cookie value and it works fine for me again!

@Dima-369
Copy link

I was able to solve it by wiping all cookies for https://bard.google.com in Firefox in the Developer Tools, logged back in with my same account. Then I noticed that the __Secure-1PSID cookie was renewed, so I used that cookie value and it works fine for me again!

After a few more usages on the same account, the same error pops up apparently, so maybe using another account is the better solution here (until that one gets the same error?).

@Yorddyyorddy
Copy link

I was able to solve it by wiping all cookies for https://bard.google.com in Firefox in the Developer Tools, logged back in with my same account. Then I noticed that the __Secure-1PSID cookie was renewed, so I used that cookie value and it works fine for me again!

yup it also works i aleady use incoginto to get cookies so no need of wiping cookies
but notice if you made so many requests in the same account you may not solve it this way bc google depends on the email used not cookie value so you might get freezed for a day
avoid using the same email for many requests

@Bharat9114
Copy link
Author

Bharat9114 commented Aug 11, 2023

It may seem like I'm giving a repetitive answer, but this is not an issue that can be resolved externally.

I have checked that the functionality of the Bard API is working properly.

Please check if there have been any account locks or policy changes from Google for your Google account or in your region.

Since the error is not reproducible and it is likely related to policies within Google's internal API interface, I cannot assist further. Please consider sharing information with others who might be experiencing similar issues.

Furthermore, as this appears to be a duplicate issue #99

I tried the way that is i deleted my account and cookies and tried again log in , it started working as usual but like after few moment again it got sucked . so i printed the error ###: Response Error: b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[7]]]\n56\n[["di",32],["af.httprm",31,"-5444954100482431325",21]]\n25\n[["e",4,null,null,131]]\n'.
Unable to get response.
Please double-check the cookie values and verify your network environment or google account.

Checking network environment or account , what is it trying to say . well i am from India , how can i find i am restricted , what this response means .

@Bharat9114
Copy link
Author

I was able to solve it by wiping all cookies for https://bard.google.com in Firefox in the Developer Tools, logged back in with my same account. Then I noticed that the __Secure-1PSID cookie was renewed, so I used that cookie value and it works fine for me again!

After a few more usages on the same account, the same error pops up apparently, so maybe using another account is the better solution here (until that one gets the same error?).

Actually i did the same used another account used its psid but again same issue rised

@hitesh22rana
Copy link

It's because Bard has updated it's policy and settings for different regions.

Here's how you can fix this. (Work's for India, might not work for users from different nations, but do give it a try)

In you session object set the following cookies as well as add the following headers.

session = requests.Session()
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = {
        "Host": "bard.google.com",
        "X-Same-Domain": "1",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.4472.114 Safari/537.36",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Origin": "https://bard.google.com",
        "Referer": "https://bard.google.com/",
 }

and then, pass this in the Bard like this, make sure to pass the token value as bard __Secure-1PSID token only and timeout is optional

Bard(token="bard __Secure-1PSID token", session=session, timeout=30)

@Dima-369
Copy link

and then, pass this in the Bard like this, make sure to pass the token value as bard __Secure-1PSID token only and timeout is optional

Does not work apparently in Germany:

Traceback (most recent call last):
  File "/Users/dima/Developer/dotfiles/python/chatbots/bard.py", line 30, in <module>
    timeout=30).get_answer(sys.argv[1]))
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bardapi/core.py", line 119, in get_answer
    "content": parsed_answer[0][0],
               ~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

@hitesh22rana
Copy link

and then, pass this in the Bard like this, make sure to pass the token value as bard __Secure-1PSID token only and timeout is optional

Does not work apparently in Germany:

Traceback (most recent call last):
  File "/Users/dima/Developer/dotfiles/python/chatbots/bard.py", line 30, in <module>
    timeout=30).get_answer(sys.argv[1]))
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bardapi/core.py", line 119, in get_answer
    "content": parsed_answer[0][0],
               ~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

can u share your code?

@dsdanielpark
Copy link
Owner

dsdanielpark commented Aug 14, 2023

Dima-369

You need to upgrade package. Check if the package version is 0.1.32.

pip install -U bardapi

@hitesh22rana
Copy link

Dima-369

You need to upgrade package. Check if the package version is 0.1.32.

pip install -U bardapi

yup maybe that's the issue @Dima-369 , or else try to share your code.

@Dima-369
Copy link

You need to upgrade package. Check if the package version is 0.1.32.

Ah, thanks guys. Yeah, that was the issue, works now!

@hitesh22rana
Copy link

Great, looks like the solution works for India as well Germany, 193 more to go lol 🤣

@dsdanielpark
Copy link
Owner

dsdanielpark commented Aug 14, 2023

Hey guys... It was already implemented.... Could you please read the readme... However, it seems like valuable information for those who didn't know. Wishing everyone a good day.

#50 #51

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

image

However, for more efficient usage with reusable sessions, it is recommended to use the code provided by hitesh22rana above.

import requests
from bardapi import Bard, SESSION_HEADERS

session = requests.Session()
token = "bard __Secure-1PSID token"
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = SESSION_HEADERS

bard = Bard(token=token, session=session)
bard.get_answer("How is the weather today in seoul?")

@Bharat9114
Copy link
Author

Bharat9114 commented Aug 14, 2023

Great, looks like the solution works for India as well Germany, 193 more to go lol 🤣

So coming to conclusion : When you import cookie from bard after 7-12 try like after 10-15 min , code again raise the same error. i tried my best to manipulate its heart code. After few attempts same issue came. Google has restricted traffic IPs i guess no third party bridge is working . In India , Neither @acheong08 nor @dsdanielpark module is permanently serving. Its because of googles policies .

can you check once if still working . Daniel mentioned same issues in readme .

@hitesh22rana
Copy link

hitesh22rana commented Aug 14, 2023

Great, looks like the solution works for India as well Germany, 193 more to go lol 🤣

So coming to conclusion : When you import cookie from bard after 7-12 try like after 10-15 min , code again raise the same error. i tried my best to manipulate its heart code. After few attempts same issue came. Google has restricted traffic IPs i guess no third party bridge is working . In India , Neither @acheong08 nor @dsdanielpark module is permanently serving. Its because of googles policies .

can you check once if still working . Daniel mentioned same issues in readme .

just checked, it's not working now 😢

@Bharat9114
Copy link
Author

Great, looks like the solution works for India as well Germany, 193 more to go lol 🤣

So coming to conclusion : When you import cookie from bard after 7-12 try like after 10-15 min , code again raise the same error. i tried my best to manipulate its heart code. After few attempts same issue came. Google has restricted traffic IPs i guess no third party bridge is working . In India , Neither @acheong08 nor @dsdanielpark module is permanently serving. Its because of googles policies .
can you check once if still working . Daniel mentioned same issues in readme .

just checked, it's not working now 😢

Hmm gotch u ! Let google update bard. Possible that they may change policy

@PythonX-001
Copy link

Please make sure to check for more efficient package management. *Please prioritize checking existing issues first. *

@dsdanielpark I tried every ways possible but getting a exception: Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'.

i checked the 1PSID value, I tried with other account, cleared browser and cookies . Earlier this was working well but from 16 days its showing same error.

Please Try to solve this problem.

i found this in the doc it worked

from bardapi import BardCookies

cookie_dict = {
    "__Secure-1PSID": "xxxxxxxx",
    "__Secure-1PSIDTS": "xxxxxxxx",
    "__Secure-1PSIDCC", "xxxxxxxx",
    # Any cookie values you want to pass session object.
}

bard = BardCookies(cookie_dict=cookie_dict)
print(bard.get_answer("こんにちは")['content'])

@EXA-Hub
Copy link

EXA-Hub commented Aug 17, 2023

Hey guys... It was already implemented.... Could you please read the readme... However, it seems like valuable information for those who didn't know. Wishing everyone a good day.

#50 #51

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

image

works for me

@Nixsr
Copy link

Nixsr commented Aug 19, 2023

I encountered the following self-explanatory error:

Exception: SNlM0e value not found in response. Check __Secure-1PSID value.

and I solved editing the cookie's dictionary in the following way because of the cookie's change

`from bardapi import BardCookies

cookie_dict = {
"__Secure-1PSID": "xxxxxxxxxxx",
"__Secure-1PSIDTS": "xxxxxxxxxxx",
"__Secure-1PAPISID": "xxxxxxxxxxx",
"__Secure-1PSIDCC": "xxxxxxxxxxx",
# Any cookie values you want to pass session object.
}

bard = BardCookies(cookie_dict=cookie_dict)
#print(bard.get_answer("What is the weather in Rome?")['content'])`

@serhaterfidan
Copy link

{
"details": "Bard API Key must be provided as token argument or extracted from browser.",
"error": "Failed to process the request."
}

Hey guys... It was already implemented.... Could you please read the readme... However, it seems like valuable information for those who didn't know. Wishing everyone a good day.

#50 #51

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

image However, for more efficient usage with reusable sessions, it is recommended to use the code provided by [hitesh22rana](https://github.com/hitesh22rana) above.
import requests
from bardapi import Bard, SESSION_HEADERS

session = requests.Session()
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = SESSION_HEADERS

bard = Bard(session=session)
bard.get_answer("How is the weather today in seoul?")

@dsdanielpark
Copy link
Owner

Check this code.

import requests
from bardapi import Bard, SESSION_HEADERS

session = requests.Session()
token = "bard __Secure-1PSID token"
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = SESSION_HEADERS

bard = Bard(token=token, session=session)
bard.get_answer("How is the weather today in seoul?")

@haseeb-heaven
Copy link

Check this code.

import requests
from bardapi import Bard, SESSION_HEADERS

session = requests.Session()
token = "bard __Secure-1PSID token"
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = SESSION_HEADERS

bard = Bard(token=token, session=session)
bard.get_answer("How is the weather today in seoul?")

This is working solution thanks.

But we are creating applications over this API and we cannot ask user to enter multiple keys from Google Bard I hope you got what I am trying to say here.
Its getting more difficult and to use this API now.

@dsdanielpark
Copy link
Owner

haseeb-heaven

You're right. This project was developed to assist in mocking some functionalities, as extending bard has been challenging for quite a while, even after the experimental version deployment (there still isn't a fully open official API).

However, with the recent development of a robust proxy server by the proxy provider, mocking various functionalities should become easier.

@fredmo
Copy link

fredmo commented Sep 19, 2023

Why don't you update the READ.ME with the information of this ticket?

@dsdanielpark
Copy link
Owner

dsdanielpark commented Sep 19, 2023

fredmo

Most of the details are described in README.md and README_DEV.md. Is there anything specific you believe needs additional updates, and if so, what is the reason?

As you may know, with APIs, there can be new errors due to unstructured issues and various interface changes. Especially in the case of services like BARD, which have different architectures depending on the country, region, and language, many users may encounter different errors and new ones.

We have tried to document the errors that can be standardized as much as possible, and marking similar user experiences can also be very helpful for developers in understanding the package. If you have more specific solutions or improvement suggestions, please let us know, and we would appreciate it.

This issue is also identical to Issue #99, but we are keeping it open to share various perspectives and situations from different people.

@QIN2DIM
Copy link

QIN2DIM commented Sep 20, 2023

Every once in a while, the cookie's value is refreshed

__Secure-1PSIDTS 
__Secure-3PSIDTS 
SIDCC 
__Secure-1PSIDCC 
__Secure-3PSIDCC 

@haseeb-heaven
Copy link

I would prefer using PALM API now its totaly free and easy to use.

@QIN2DIM
Copy link

QIN2DIM commented Sep 21, 2023

@haseeb-heaven Is the PALM API an open use feature? I think I'm still at Waitlist (

@haseeb-heaven
Copy link

@haseeb-heaven Is the PALM API an open use feature? I think I'm still at Waitlist (

Yes its open to use and totally free i am using its pretty fast.

@jamesljl
Copy link

jamesljl commented Oct 16, 2023

It's because Bard has updated it's policy and settings for different regions.

Here's how you can fix this. (Work's for India, might not work for users from different nations, but do give it a try)

In you session object set the following cookies as well as add the following headers.

session = requests.Session()
session.cookies.set("__Secure-1PSID", "bard __Secure-1PSID token")
session.cookies.set( "__Secure-1PSIDCC", "bard __Secure-1PSIDCC token")
session.cookies.set("__Secure-1PSIDTS", "bard __Secure-1PSIDTS token")
session.headers = {
        "Host": "bard.google.com",
        "X-Same-Domain": "1",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.4472.114 Safari/537.36",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Origin": "https://bard.google.com",
        "Referer": "https://bard.google.com/",
 }

and then, pass this in the Bard like this, make sure to pass the token value as bard __Secure-1PSID token only and timeout is optional

Bard(token="bard __Secure-1PSID token", session=session, timeout=30)

it's worked for me first, after several times, it failed !

@agilebean
Copy link

Did anybody find a working solution meanwhile?
I just tried the cookie_dict solution which worked for about 5 requests and threw the SNlM0e value not found error.
I'm disappointed at Google for making Bard so difficult to access. We cannot blame this repository for it.

@vibheksoni
Copy link

vibheksoni commented Oct 20, 2023

Hey guys after looking a bit into the problem the error SNlM0e value not found you can hard code the value simple go into browser make request to https://bard.google.com/ and then get the SNlM0e

edit the modules code

def _get_snim0e(self) -> str:
        """
        Get the SNlM0e value from the Bard API response.

        Returns:
            str: SNlM0e value.
        Raises:
            Exception: If the __Secure-1PSID value is invalid or SNlM0e value is not found in the response.
        """
        # if not self.token or self.token[-1] != ".":
        #     raise Exception(
        #         "__Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value."
        #     )
        # resp = self.session.get(
        #     "https://bard.google.com/", timeout=self.timeout, proxies=self.proxies
        # )
        # if resp.status_code != 200:
        #     raise Exception(
        #         f"Response status code is not 200. Response Status is {resp.status_code}"
        #     )
        # snim0e = re.search(r"SNlM0e\":\"(.*?)\"", resp.text)
        # if not snim0e:
        #     raise Exception(
        #         "SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'."
        #     )
        # return snim0e.group(1)
        return "HARDCODED VALUE"
   and use bard simply
   
   Here is how my main looks like atm
import os, requests, json

os.environ['_BARD_API_KEY'] = ''

session = requests.Session()

with open('cookies.json') as f:
    cookies = json.load(f)
    for cookie in cookies:
        session.cookies.set(cookie['name'], cookie['value'])

session.headers = {
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'en-US,en;q=0.9',
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    'Origin': 'https://bard.google.com',
    'Referer': 'https://bard.google.com/',
    'Sec-Ch-Ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
    'Sec-Ch-Ua-Arch': '""',
    'Sec-Ch-Ua-Bitness': '"64"',
    'Sec-Ch-Ua-Full-Version': '"118.0.5993.88"',
    'Sec-Ch-Ua-Full-Version-List': '"Chromium";v="118.0.5993.88", "Google Chrome";v="118.0.5993.88", "Not=A?Brand";v="99.0.0.0"',
    'Sec-Ch-Ua-Mobile': '?1',
    'Sec-Ch-Ua-Model': '"Nexus 5"',
    'Sec-Ch-Ua-Platform': '"Android"',
    'Sec-Ch-Ua-Platform-Version': '"6.0"',
    'Sec-Ch-Ua-Wow64': '?0',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Mobile Safari/537.36',
    'X-Client-Data': 'GET FROM THE HEADERS',
    'X-Same-Domain': '1'
}

bard = Bard(session=session, timeout=30)
bard_answer = bard.get_answer("Do you like cookies?")['content']
print(bard_answer)```

Hopefully you guys find this helpful

@vibheksoni
Copy link

Maybe the dev should add option for hard coded snim0e value too

@vibheksoni
Copy link

Few things to mention

In headers you need X-Client-Data
For snim get hardcoded value

and you should be good

@requizm
Copy link

requizm commented Oct 21, 2023

In headers you need X-Client-Data

@vibheksoni I couldn't find it in the headers. Which request exactly? I checked GET / and POST /_/BardChatUi/data/batchexecute

@vibheksoni
Copy link

vibheksoni commented Oct 21, 2023

Im talking about request to streamGenerate

@requizm
Copy link

requizm commented Oct 21, 2023

@vibheksoni I see. X-Client-Data is feature of Google Chrome(Chrome Variations). I don't think this is related to the issue. Anyway, I tried with X-Client-Data and hardcoded snim0e, it gives another error :(

Response Error: b')]}\'\n\n38\n[["wrb.fr",null,null,null,null,[7]]]\n55\n[["di",45],["af.httprm",45,"2456398038102412256",46]]\n25\n[["e",4,null,null,130]]\n'. 
Unable to get response.
Please double-check the cookie values and verify your network environment or google account.

Also, cookie_dict method sometimes works. Sometimes, it's not. It is not stable.

@vibheksoni
Copy link

Oh ok yea I was trying all these solutions then I started looking at the modules code and the sites network tab and those helped me not get any errors or captcha. The problem is that there is a captcha task when I displayed the request contents. Im probably gonna write a version using selenium so I can solve or evade captcha for the most part.

@x4080
Copy link

x4080 commented Dec 7, 2023

Got any success with latest bard with gemini ?

@SetoKaiba
Copy link

#254
I created a PR that may solve this problem. At least, for me, use the whole cookies will solve the problem.

@x4080
Copy link

x4080 commented Dec 28, 2023

@SetoKaiba Thanks, I'll check it out

@chris-cannon90
Copy link

I would prefer using PALM API now its totaly free and easy to use.

Most underrated comment in this thread by far. I know it doesn't solve the potential issue with this library, but if you just need to get up and running I recommend Google's AI Studio. Navigate here to create an API key. Review the Python quickstart here. You'll be off to the races in no time.

@dsdanielpark
Copy link
Owner

dsdanielpark commented Feb 6, 2024

I highly recommended to pass clear variable like (‘token’=‘xxxxxx’) not (os.environ[‘_BARD_API’] = ‘xxxxxx’)

Please refer official google api issue page.

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

No branches or pull requests