acheong08 / Bard

Python SDK/API for reverse engineered Google Bard
MIT License
1.42k stars 179 forks source link

SNlM0e (Compiled thread) #31

Open acheong08 opened 1 year ago

acheong08 commented 1 year ago
acheong08 commented 1 year ago

Attempts to solve:

kjenney commented 1 year ago

I'm seeing the same error. My IP address is in the US, and I'm only signed in to one account.

jonrhaider commented 1 year ago

For everyone's convenience (as an easy meanwhile solution while this is being resolved), you can obtain the SNlM0e directly from your Bard browser session. I mean if you were already going to open the dev tools in that window to get the cookie from 'Applications' tab, might as well just use console.log(WIZ_global_data.SNlM0e); in the console window to get the SNlM0e value, then you could copy and paste both in one trip to the browser window.

kjenney commented 1 year ago

How do you get the module to use the value that you've extracted?

jonrhaider commented 1 year ago

How do you get the module to use the value that you've extracted?

Similar to how you pass the cookie string value to the Bard.py script

bard () {
    export BARD_QUICK=true
    export BARD_SESSION=<REDACTED>.
    python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7
}

you could do the same for SNlM0e:

        export BARD_SNlM0e=<REDACTED>.

Then you could modify your __get_snlm0e(self): function to just call it from os env and avoid the whole api request:

def __get_snlm0e(self):
        SNlM0e= os.getenv("BARD_SNlM0e")
        return SNlM0e

I do something similar using NodeJS in my project DuelGPT (a front-end for using ChatGPT and Bard side-by-side - minimal backend code)

kjenney commented 1 year ago

Exporting SNlM0e from console gives me a different error:

Google Bard encountered an error:
b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[7]]]\n56\n[["di",52],["af.httprm",51,"-8317639822438177330",23]]\n25\n[["e",4,null,null,131]]\n'.
Delamcode commented 1 year ago

Exporting SNlM0e from console gives me a different error:

Google Bard encountered an error:
b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[7]]]\n56\n[["di",52],["af.httprm",51,"-8317639822438177330",23]]\n25\n[["e",4,null,null,131]]\n'.

Yep having this too…

karlzipple commented 1 year ago

Works great when I call it from the command line, but when I try to use it in a script I keep getting the same error.

from Bard import Chatbot  
token = "Current Cookie Value"  
chatbot = Chatbot(token)  
chatbot.ask("Hello, how are you?")

produces 'NoneType' object is not iterable. I'm sure I'm missing something obvious

YanJiaHuan commented 1 year ago

@karlzipple You can go to Bard.py to change the functionality of 'def ask(self, message: str) -> dict:', print out the 'json_chat_data' to see what is your task-oriented requirement, and customize the 'results' yourself to skip the Nonetype error. That could be a cheap solution.

fractaldna22 commented 1 year ago

How do you get the module to use the value that you've extracted?

Similar to how you pass the cookie string value to the Bard.py script

bard () {
  export BARD_QUICK=true
  export BARD_SESSION=<REDACTED>.
  python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7
}

you could do the same for SNlM0e:

        export BARD_SNlM0e=<REDACTED>.

Then you could modify your __get_snlm0e(self): function to just call it from os env and avoid the whole api request:

def __get_snlm0e(self):
        SNlM0e= os.getenv("BARD_SNlM0e")
        return SNlM0e

I do something similar using NodeJS in my project DuelGPT (a front-end for using ChatGPT and Bard side-by-side - minimal backend code)

can you please retype this. What the hell is . ? Does it contain < > ? Does it end with a period? <1687168999467>. ? is it ? is it DFuTz6sfj1k3Bu814Vj8_3JhXhvE:1687168999467? is it "DFuTz6sfj1k3Bu814Vj8_3JhXhvE:1687168999467" ? Please. Be specific.

kjenney commented 1 year ago

The latest release resolves this issue. You don't need to make any modifications to the code for this to work. Just pull main.

Here's my working code, copied from the README.md in ~/.bash_profile

# USAGE1: bard QUESTION
# USAGE2: echo "QUESTION" | bard
bard () {
    export BARD_QUICK=true
        export BARD_SESSION="REDACTED"
    python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7
}

Here's an example of it working:

$ bard "What is the capital of Argentina?"
/usr/local/lib/python3.10/site-packages/Bard.py:62: DeprecationWarning: There is no current event loop
  self.loop = asyncio.get_event_loop()
The capital of Argentina is Buenos Aires. It is the most populous city in Argentina, with a metropolitan area of over 15 million people.
Buenos Aires is located on the western shore of the Río de la Plata, on South America's southeastern coast. The city was founded in 1536
by Spanish colonists, and it became the capital of Argentina in 1880. Buenos Aires is a major economic, cultural, and political center in
South America. It is home to the Argentine National Congress, the Supreme Court of Argentina, and the Casa Rosada, the official residence
of the President of Argentina. Buenos Aires is also a major center for tourism, with a wide variety of attractions, including museums,
theaters, restaurants, and nightlife.
fractaldna22 commented 1 year ago

i still cant get it to work :( Im using the chatbot usecase, with ChatGPT-DIscord-Bot-1.5.1. By commenting out the errors and pasting in the SNlM0e directly instead of using the __Secure_1*** cookie, because it gives me the "must end with a dot" error even though it DOES end with a dot, i finally get it to fully load the discord bot, but when i go to get a response it says Google Bard encountered an error: b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[7]]]\n56\n[["di",60],["af.httprm",60,"-8234551735768967562",38]]\n25\n[["e",4,null,null,131]]\n'. I know its still related to the cookie.

I dont know how bard () { export BARD_QUICK=true export BARD_SESSION="REDACTED" python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7 }

relates in any possible way

fractaldna22 commented 1 year ago
async def __get_snlm0e(self):
        # Find "SNlM0e":"<ID>"
        #if not self.session_id or self.session_id[-1] != ".":
        #    raise Exception(
        #         "__Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value.",
        #    )
        resp = await self.session.get(
            "https://bard.google.com/",
            timeout=10,
            follow_redirects=True,
        )
        if resp.status_code != 200:
            raise Exception(
                f"Response code not 200. Response Status is {resp.status_code}",
            )
        SNlM0e = re.search(r"SNlM0e\":\"(.*?)\"", "AFuTs6sfj1k3Bu814Vj8_3JhXhvE:1687168999468")
        ##if not SNlM0e:
        #    raise Exception(
        #        "SNlM0e value not found in response. Check __Secure-1PSID value.",
        #    )
        return "(.1687168999468?)"
dhnam commented 1 year ago

Worked yesterday; Not working today. I wonder why it happen, but getting site with cURL (with and without cookie) doesn't include SNlM0e too.