-
-
Notifications
You must be signed in to change notification settings - Fork 527
Issue is still there Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'. #99
Comments
Not package-related issue, but possible action on the account due to unauthorized usage (excessive traffic).I have confirmed that there are no major issues with the current functioning of the package, and it is operating normally. As mentioned in various issues and the README.md, bardapi was implemented to support developers in mocking and implementing certain testing functionalities before the official package distribution of bard. Please note that the token values used are associated with Google accounts. This particular issue could be a precautionary measure against unauthorized usage (such as excessive traffic), and if you continue to use it, there is a possibility of encountering issues with your Google account. Therefore, I strongly advise against using this package to generate excessive traffic and recommend checking the official API documentation instead. Therefore, various types of errors (Nonetype, SNIM0e value, Response Error) may occur, but these are not package-related issues and could be actions taken by Google regarding the account. We recommend trying with the
|
There is no issue int this API. The reason we get : Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx' How can you get rid of it:
Re run and you are good to go. |
Admin. We need use two cookies - __Secure-1PSID and __Secure-1PSIDTS. Without __Secure-1PSIDTS html page bard.google.com has unauthorized user. |
If you need to set multi cookie value. Using Bard Cookies Object. from bardapi import BardCookies
cookie_dict = {
"__Secure-1PSID": "xxxxxxxxx",
"__Secure-1PSIDTS": "xxxxxxxxx",
# Any cookie values you want to pass session object.
}
bard = BardCookies(cookie_dict=cookie_dict)
print(bard.get_answer("こんにちは")) |
On Windows, importing BardCookies is not possible: >>> from bardapi import BardCookies
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'BardCookies' from 'bardapi' (C:\Program Files\Python310\lib\site-packages\bardapi\__init__.py) |
Upon rechecking, I confirmed that there were no issues with the implementation of Additionally, I remembered that it was separated as a standalone entity to avoid any potential issues arising in the Check version and you can use from bardapi import BardCookies
cookie_dict = {
"__Secure-1PSID": "xxxxxxxxx",
"__Secure-1PSIDTS": "xxxxxxxxx",
"__Secure-1PSIDCC", "xxxxxxx")
}
bard = BardCookies(cookie_dict=cookie_dict)
print(bard.get_answer("こんにちは")) |
But there is a workaround for this looking at the code:
Wouldn't it be possible to pass a dictionary with cookies along? |
Here in Austria, it doesn't work with just the one token. Unfortunately I can't help currently as I don't have an IDE here and can't install one, I am trying all of this on Windows in Notepad++ plus CLI :/ |
this work for me |
You can still use the However, due to my current commitments to another project, I won't be able to address any additional issues that may arise. Therefore, I have decided to maintain this version as it is for now. The development priority has been postponed until a later time when I can address any issues and focus on adding new features. Anyone is welcome to contribute at any time. How to use BardCookiesBardCookies works fine without any differences on both Windows and Linux. Please reinstall it to ensure you have the latest version.
import bardapi
bardapi.__version__
>>> '0.1.24'
from bardapi import BardCookies
cookie_dict = {
"__Secure-1PSID": "xxxxxxxxx",
"__Secure-1PSIDTS": "xxxxxxxxx",
"__Secure-1PSIDCC", "xxxxxxx")
}
bard = BardCookies(cookie_dict=cookie_dict)
print(bard.get_answer("こんにちは")) For more feature of Bard-API package, please check this document. |
import requests
from bardapi.constants import SESSION_HEADERS
from bardapi import Bard
import json
import os
def load_cookie(element_name):
with open(os.getcwd() + "/" + "bard.json", "r", encoding="utf-8") as file:
data = json.load(file)
if isinstance(data, list):
for item in data:
if item.get("name") == element_name:
return item.get("value")
return None
_1PSID = load_cookie("__Secure-1PSID")
_1PSIDTS = load_cookie("__Secure-1PSIDTS")
_1PSIDCC = load_cookie("__Secure-1PSIDCC")
session = requests.Session()
session.headers = SESSION_HEADERS
session.cookies.set("__Secure-1PSID", _1PSID)
session.cookies.set("__Secure-1PSIDTS", _1PSIDTS)
session.cookies.set("__Secure-1PSIDCC", _1PSIDCC)
bard = Bard(token=_1PSID, session=session)
print(bard.get_answer("gnomes")['content']) this working if put in the heart of the api would be better. just passing the json location to get the data |
Same problem when trying to access Bard from Hungary. __Secure-1PSIDTS needs to be included in the request, and it needs to be rotated every ~20minutes. In the chromium source it is called a bound session cookie: |
so in this case it would be reloading each question now the section just use __Secure-1PSID? |
Yes, cookies need to be rotated. |
Ok, so the million dollar question is: can we do this without a browser? Because having to replace this cookie manually every 10-20 minutes is bad news for my use case. |
While support for this issue is available from version 0.1.26 onwards, it may still be challenging to find a definitive solution. Auto Cookie BardUsing browser_cookie3 we extract the `__Secure-1PSID`` cookie from all browsers, and then we can use the API without passing the token. However, there are still incomplete dependency packages and various variables, so please seek assistance in the following GitHub Issues or adjust your browser's version. from bardapi import Bard
bard = Bard(token_from_browser=True)
res = bard.get_answer("Do you like cookies?")
print(res) |
Going to Incognito and collecting the cookie (from the new signin inside incognito) seems to help. |
I agree with @rajserc. The issue seems to be related to being signed to multiple Google accounts in the same browser session. I suppose it's worth a try to log out of all but one account before capturing the Bard token. |
browser_cookie3 using the firefox version it seems that you have to get the sessionstore.js file if that's the case you could make the bard api read this file and that's it it will work continuously and lastingly |
it worked for me with out using json |
works for me! |
Works fine! |
Here is chrome extension to get Cookies : |
please use latest version |
clear browser cookies and then try with new cookies data it worked for me :D |
It's my first time using it, but your solution actually fixed it for me. Thanks! |
Hello all, Set your input textinput_text = "Why is the sky blue?"input_text = "What is the current status of Ashes Series 2023" 1 frames /usr/local/lib/python3.10/dist-packages/bardapi/core.py in _get_snim0e(self) 114 """ 115 if not self.token or self.token[-1] != ".": --> 116 raise Exception( 117 "__Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value." 118 ) Exception: __Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value. |
Is this code work?
```
token = "Insert.API here"
input_text = "What is the current status of Ashes Series 2023"
print(Bard(token).get_answer(input_text)['content'])`
```
|
I know I gave me the error message I have said above. It says something about the API can't be Authorised. |
I just simply clear cookies, refresh bard,google.com then re-copied the 1PSID then it worked. |
THANKS WORKED |
Tested and verified above, same issue in Sri Lanka, the __Secure-1PSIDTS rotates every ~20mins. Secure-1PSID & Secure-1PSIDCC can be kept the same, but we have to manually retrieve the Secure-1PSIDTS key every 20 mins.
|
how to refresh and get new __Secure-1PSIDTS or __Secure-3PSIDTS by java code? i block all xhr request with out https://mobilesdk-pa.clients6.google.com/v1/projects/xxxx:queryBilledUsage, and browser try create new token and get succes. I think __Secure-3PSIDTS generated by javascript. |
I fix it by update cookie after every request |
Thank you! It is working......... |
I've been experimenting with the Bard API for some time now, and I seem to be encountering a couple of problems that I hope someone can help me clarify. The main objective is to upload images via the Bard API. While I have managed to get this working, I've noticed that the tokens refresh frequently. When processing a batch of 50-100 images, the tokens tend to change after the first 5 responses. I've been following the discussion in this thread and tried implementing While I have access to Visual Question Answering (VQA), I find the Bard UI more user-friendly. The prompt length restriction (80 tokens max) in VQA also makes Bard a more preferable option. If anyone has managed to resolve the token refresh issue without having to manually update the tokens each time, I would greatly appreciate your insights. Here's the current script that I'm using: import requests
from bardapi import Bard, SESSION_HEADERS
from PIL import Image
import pandas as pd
import io
def main():
session = requests.Session()
token = "insert here"
# Set your cookies
session.cookies.set("__Secure-1PSID", token)
session.cookies.set("__Secure-1PSIDCC", "insert here")
session.cookies.set("__Secure-1PSIDTS", "insert here")
# Set the session headers
session.headers = SESSION_HEADERS
# Send an API request and get a response
bard = Bard(token=token, session=session)
# Load the text file and read the URLs
with open('C:\\Users\\Downloads\\SectionalShape.txt', 'r') as f:
urls = f.readlines()
# Iterate over the URLs
for url in urls:
url = url.strip() # Remove leading/trailing whitespace (including newline)
# Get the image from the URL
response = requests.get(url)
# Debug: Print the status code and content type of the response
print(f"Status code: {response.status_code}")
print(f"Content-Type: {response.headers['content-type']}")
try:
# Open the image and convert it to bytes
image = Image.open(io.BytesIO(response.content))
byte_arr = io.BytesIO()
image.save(byte_arr, format='JPEG')
image_data = byte_arr.getvalue()
except UnidentifiedImageError:
print(f"Unable to open image from URL: {url}")
continue
# Ask the Bard API about the image
bard_answer = bard.ask_about_image('What is in the image?', image_data)
# Write the URL and response to the text file
with open('C:\\Users\\Downloads\\SectionalShape.txt', 'a') as f:
f.write(f"{url},{bard_answer['content']}\n")
if __name__ == "__main__":
main() Thank you in advance! |
I created function get cookies from chorme. You can fix the error PermissionError: [Errno 13] Permission denied at borisbabic/browser_cookie3#180 (comment) def _extract_bard_cookie() -> dict:
cookie_dict = {}
cj = browser_cookie3.chrome(cookie_file=r'C:\Users\<your user>\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies',domain_name=".google.com")
for cookie in cj:
if cookie.name == "__Secure-1PSID" and cookie.value.endswith("."):
cookie_dict["__Secure-1PSID"] = cookie.value
if cookie.name == "__Secure-1PSIDTS":
cookie_dict["__Secure-1PSIDTS"] = cookie.value
if cookie.name == "__Secure-1PSIDCC":
cookie_dict["__Secure-1PSIDCC"] = cookie.value
logging.info(cookie_dict)
return cookie_dict |
I tried that but im getting permission denied is this still working for you?
|
Try running the terminal with admin and remember to restart Chrome |
After restarting Chrome, the implementation is functioning as expected. Currently, requests to Google API are made sequentially, awaiting each response before proceeding to the next. Given this setup, I'm interested to know if you has encountered rate limiting or blocks from Google. The plan is to make 100-200 sequential calls. There's a segment of code dedicated to updating cookies after each request: # Update cookies after every request
cookies = []
for k, v in bard.session.cookies.get_dict().items():
cookies.append({'name': k, 'value': v}) Is this necessary. Here is the complete updated code: Click to expand!````python import requests from bardapi import Bard, SESSION_HEADERS from PIL import Image from PIL import UnidentifiedImageError import pandas as pd import io import json import browser_cookie3def _extract_bard_cookie() -> dict: def main():
if name == "main":
|
I once ran 20 requests at once, nothing happened. You can ask bard, it seems unlimited requests. bard is still in beta. Still, you should be cautious |
I was running through intelli J one request after the other and at around 80-90 i got blocked, now even when i try directly through the Bard web UI directly it doesnt go through. i tried another google account and it works but when im using the script im getting stopped. |
Probably because of my area, you can ask bard or find bard policy |
SNlM0e value not found in response. Check __Secure-1PSID value. This error resolve with clear cookies and repost in own code So your code is runing smooth |
My Solution to this issue
|
[NOTICE] Please, go to Gemini-API https://github.com/dsdanielpark/Gemini-API Google - Gemini APIA 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. Installationpip install python-gemini-api pip install git+https://github.com/dsdanielpark/Gemini-API.git For the updated version, use as follows:
|
Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'.****
The text was updated successfully, but these errors were encountered: