dsdanielpark / Bard-API

The unofficial python package that returns response of Google Bard through cookie value.

Home Page:https://pypi.org/project/bardapi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: AsyncClient.post() got an unexpected keyword argument 'proxies'

myreallycoolusername opened this issue · comments

This is my code (I was trying to make a TTS API):

@app.route('/tts', methods=['GET'])
async def tts():
   # codes bla bla bla
   text = request.args.get('input', 'Empty')
   # codes here bla bla bla..
   audio = await bard.speech(text)
   directory = 'static'
   if not os.path.exists(directory):
       os.makedirs(directory)
       filename = str(uuid.uuid1()) + ".mp3"
       file_path = os.path.join(directory, filename)
       with open(file_path, "wb") as f:
           f.write(bytes(audio.get('audio', ''), encoding='utf-8'))
           executor.submit_stored('delete_file_' + filename, delete_file, file_path, time.time() + 300)
           return redirect(url_for('static', filename=filename))
           run(tts())

def delete_file(file_path, delete_time):
   while time.time() < delete_time:
       time.sleep(1)
       if os.path.exists(file_path):
           os.remove(file_path)

Then I got this error:

audio = await bard.speech(text)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.12/site-packages/bardapi/core_async.py", line 365, in speech
    resp = await self.client.post(
                 ^^^^^^^^^^^^^^^^^
TypeError: AsyncClient.post() got an unexpected keyword argument 'proxies'

Is there a solution for this error?

Thank you for reporting the error.

I am currently working on fixing and feature testing the asynchronous bard. It is expected to function correctly in version 0.1.39.

Additionally, any contributions are welcome, so please feel free to submit a pull request.

Thank you.

This issue has been resolved in bardapi version 0.1.39. Thank you for reporting the issue.

Bard API - version 0.1.39

$ pip install bardapi==0.1.39
$ pip install -q -U bardapi

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

from httpx import AsyncClient
from bardapi import BardAsync
import os

# Uncomment and set your API key as needed
# os.environ['_BARD_API_KEY'] = 'xxxxxxx'
token = 'xxxxxxx'  # Replace with your actual 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.0.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/",
}
timeout = 30  # Example timeout
proxies = {}  # Replace with your proxies if needed

client = AsyncClient(
    http2=True,
    headers=SESSION_HEADERS,
    cookies={"__Secure-1PSID": token},
    timeout=timeout,
    proxies=proxies,
)

bard_async = BardAsync(token=token, client=client)

# Asynchronous function to get the answer
async def get_bard_answer(question):
    await bard_async.async_setup()  # Ensure async setup is done
    return await bard_async.get_answer(question)

response = await get_bard_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")
print(response['content'])