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

TypeError: Cannot read properties of undefined (reading '0') #21

Closed
Ja-Sa-La opened this issue May 30, 2023 · 7 comments
Closed

TypeError: Cannot read properties of undefined (reading '0') #21

Ja-Sa-La opened this issue May 30, 2023 · 7 comments

Comments

@Ja-Sa-La
Copy link

Ja-Sa-La commented May 30, 2023

Hello, I'm not sure what happened, but after using this fine for a month or so all of a sudden, I keep getting the following error. Also as an attachment is a response for the request (cookie censored), using node 18.16.0 with googlebard 1.0.6

response.txt

file:///root/nodejs/yetanotherbot/node_modules/googlebard/dist/classes/bard.js:175
return resData[0];
^

TypeError: Cannot read properties of undefined (reading '0')
at Bard.ask (file:///root/nodejs/yetanotherbot/node_modules/googlebard/dist/classes/bard.js:175:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///root/nodejs/yetanotherbot/aiHelper.js:58:21

@ruanmus
Copy link

ruanmus commented May 31, 2023

Me too

@OliverwengFiltered
Copy link

yea, I have the same issue,

it works with my local machine.

but once the code pushed to cloud server, it throws this error.

is it because the server is behind the reverse proxy ?

@OliverwengFiltered
Copy link

this is the error message I'm getting

Error parsing response: make sure you are using the correct cookie, copy the value of "__Secure-1PSID" cookie and set it like this: 

new Bard("__Secure-1PSID=<COOKIE_VALUE>")

Also using a US proxy is recommended.

If this error persists, please open an issue on github.
https://github.com/PawanOsman/GoogleBard

I'm pretty sure, my server is deployed under US-central-1 region and the cookie value is presented in the code. and it works on the local machine.

@mehul-srivastava
Copy link
Contributor

Hello @Ja-Sa-La! Could you please share your source code so that I can pinpoint the cause of this issue?

@Ja-Sa-La
Copy link
Author

Ja-Sa-La commented Jun 3, 2023

Hey @mehul-srivastava, relevant parts to the code are here:

import {Bard} from "googlebard"; let cookies = "__Secure-1PSID=cookie here"; let bot = new Bard(cookies);

export async function GoogleWithoutModifiers(textToSend) { return new Promise(async (resolve, reject) => { console.log("GoogleWithoutModifiers"); let conversationId = makeid(10); let response = {text: String, convoid: String}; response.text = await bot.ask(textToSend, conversationId); query("INSERT INTO AI (engine, Data) VALUES (?,?)", ["Google", conversationId], await function (err, results, fields) { response.convoid = results.insertId; return resolve(response); }) })}

function makeid(length) { let result = ''; const characters = '0123456789'; const charactersLength = characters.length; let counter = 0; while (counter < length) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); counter += 1; } return result; }

Edit:
It would seem like it's only an issue when the bot is running on my VPS. Both I and the server are using the same open VPN server to send the requests, so I am not exactly sure what the issue could be.

@mehul-srivastava
Copy link
Contributor

This exact piece of code works perfectly for me. I still think there might be an issue with the cookie. This may happen if you are using some other google account to interact with bard.google.com but using the cookie as __Secure-1PSID=.

I have written about it here - https://github.com/PawanOsman/GoogleBard#prerequisite---how-to-get-cookies. (how different account corresponds to a different cookie like __Secure-3PSID=)

If you followed the documentation well but still receiving an error, maybe try clearing cookies from your browser once and copy the new cookie from the official website.
If you still face an issue, there is something else that needs to be looked into.

@Ja-Sa-La
Copy link
Author

Ja-Sa-La commented Jun 3, 2023

yeah, i was able to confirm it as working as well. on my local machine. though still on the VPS it fails to get any info using the same IP. Bing/chatgpt queries are working fine with chatgpt-api & bing-chat & Imagen via api.pawan.krd. vps is running almalinux 8

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

No branches or pull requests

5 participants