Giter Club home page Giter Club logo

Comments (9)

schneibe avatar schneibe commented on June 3, 2024 9

This solved my problem (i.e., create a cookie dictionary and add values for __Secure-1PSIDTS and __Secure-1PSIDCC in addition to __Secure-1PSID)

from bardapi import BardCookies

cookie_dict = {
    "__Secure-1PSID": "xxxxxxxxx",
    "__Secure-1PSIDTS": "xxxxxxxxx",
    "__Secure-1PSIDCC":"xxxxxxxxx"
}

bard = BardCookies(cookie_dict=cookie_dict)

print(bard.get_answer("Hello"))

from bard-api.

EEG20 avatar EEG20 commented on June 3, 2024

i've fixed the problem but i have another problem

code :

from bardapi import Bard
import os

import requests

Get your proxy url at crawlbase https://crawlbase.com/docs/smart-proxy/get/

proxy_url = "[email protected]:8012"
proxies = {"http": proxy_url, "https": proxy_url}
bard = Bard(token='...', proxies=proxies, timeout=30)
bard.get_answer("hello")['content']

problem :
Traceback (most recent call last):
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 711, in urlopen
self._prepare_proxy(conn)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1007, in prepare_proxy
conn.connect()
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 419, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl
.py", line 449, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl
.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 798, in urlopen
retries = retries.increment(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='bard.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\Users\neveu\OneDrive\Bureau\ay\test.py", line 10, in
bard = Bard(token='cwi5OPgUf7KEaHnG8v7_CvyITY4GN_u5qumIkZDuEGJrm9vO35j7VRwSW4NhUIwnxMmWjw.', proxies=proxies, timeout=30)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\bardapi\core.py", line 78, in init
self.SNlM0e = self._get_snim0e()
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\bardapi\core.py", line 145, in _get_snim0e
resp = self.session.get(
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 602, in get
return self.request("GET", url, **kwargs)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "C:\Users\neveu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='bard.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)')))

from bard-api.

schneibe avatar schneibe commented on June 3, 2024

how did you fix the "Exception: Response status code is not 200. Response Status is 404"? I am having the same issue

from bard-api.

EEG20 avatar EEG20 commented on June 3, 2024

how did you fix the "Exception: Response status code is not 200. Response Status is 404"? I am having the same issue

The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource. Links that lead to a 404 page are often called broken or dead links and can be subject to link rot. A 404 status code only indicates that the resource is missing: not whether the absence is temporary or permanent.

The HTTP 409 Conflict response status code indicates a request conflict with the current state of the target resource. Conflicts are most likely to occur in response to a PUT request.

It seems there is a conflict with the local resources designated as a proxy server because the local server is unable to act as a proxy. I recommend using an appropriate proxy server.

from bard-api.

useris20x avatar useris20x commented on June 3, 2024

It looks like the problem is in the cookies: __Secure-1PSIDTS and __Secure-1PSIDCC values. It needs for usage and often changes it.

from bard-api.

s11ngh avatar s11ngh commented on June 3, 2024

This solved my problem (i.e., create a cookie dictionary and add values for __Secure-1PSIDTS and __Secure-1PSIDCC in addition to __Secure-1PSID)

from bardapi import BardCookies

cookie_dict = {
    "__Secure-1PSID": "xxxxxxxxx",
    "__Secure-1PSIDTS": "xxxxxxxxx",
    "__Secure-1PSIDCC":"xxxxxxxxx"
}

bard = BardCookies(cookie_dict=cookie_dict)

print(bard.get_answer("Hello"))

I just tried this but I get an error indicating too many requests:

Exception: Response status code is not 200. Response Status is 429

Any idea how I can get the API working?

from bard-api.

artur-romao avatar artur-romao commented on June 3, 2024

This solved my problem (i.e., create a cookie dictionary and add values for __Secure-1PSIDTS and __Secure-1PSIDCC in addition to __Secure-1PSID)

from bardapi import BardCookies

cookie_dict = {
    "__Secure-1PSID": "xxxxxxxxx",
    "__Secure-1PSIDTS": "xxxxxxxxx",
    "__Secure-1PSIDCC":"xxxxxxxxx"
}

bard = BardCookies(cookie_dict=cookie_dict)

print(bard.get_answer("Hello"))

This works, but just temporarily, because __Secure-1PSIDTS and __Secure-1PSIDCC are frequently changing.
You should fetch the cookies every once in a while.

from bard-api.

myreallycoolusername avatar myreallycoolusername commented on June 3, 2024

Not sure if this is helpful but I found the thing that gave the 404 error:
`Request sent to https://consent.google.com/m

{
http.fragment: , 
http.method: GET, 
http.query: continue=https://bard.google.com/?hl%3Den&gl=DE&m=0&pc=bard&cm=2&hl=en&src=1, 
http.response.status_code: 404, 
reason: Not Found
}
```

from bard-api.

dsdanielpark avatar dsdanielpark commented on June 3, 2024

Please referes #112, #229, #248, #259 and FAQ.

from bard-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.