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

[error]: /turing/conversation/create: failed to parse response body #370

Closed
leoleaf opened this issue May 24, 2023 · 5 comments
Closed

[error]: /turing/conversation/create: failed to parse response body #370

leoleaf opened this issue May 24, 2023 · 5 comments

Comments

@leoleaf
Copy link

leoleaf commented May 24, 2023

hello, guys. this project is really fantastic, i have been using it for a while time. but,yesterday,when i asked bingAI,it returned a error. Have you ever see this error?

An error occurred. Please try again in a few moments. Error message: /turing/conversation/create: failed to parse response body.
...

response body is a html. i put it into chrome. the follow is something which chrome show.
image

@danny-avila
Copy link
Owner

danny-avila commented May 24, 2023

Hi, yes it seems Bing has updated something on their end but I have a solution for you. Update the project to latest on main branch, I also posted this here: waylaidwanderer/node-chatgpt-api#378 (comment) and updated the project accordingly here #369

You will need to set BINGAI_TOKEN in your ./api/.env file (or in your browser if using "user_provided") to your full cookies string from bing.com, instead of just the U= value.

This is confirmed working for me

image

Using firefox and dev tools, i get my cookies string from here:

image


You can use any browser, just fish around in the network tab to see which request has a Cookie value in the Request headers

image

Thanks for checking out the project, I'm glad you're enjoying it!

@danny-avila
Copy link
Owner

@feng2505664393 let me know if the above worked for you

There were also some other suggestions at the bottom of this issues page waylaidwanderer/node-chatgpt-api#378

@leoleaf
Copy link
Author

leoleaf commented May 24, 2023

@feng2505664393 let me know if the above worked for you

There were also some other suggestions at the bottom of this issues page waylaidwanderer/node-chatgpt-api#378

Sorry, sir. I used an old version of chat-clone. In order to try the solution you provided, I had to update my Docker image. It took me some time, but the exciting thing is that I just finished all the work on the solution and it works!
Hahaha, thank you.

@danny-avila
Copy link
Owner

Awesome, glad to help!

@rraymondgh
Copy link

if like me you do not like manual steps to derive BING_API_TOKEN configuration, this can be automated

if __name__ == "__main__":
    token = get_bing_api_token("username", "password")
    print(token)

python selenium function to get BING_API_TOKEN
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException as STimeout
from http.cookies import SimpleCookie
import json
import time

def get_bing_api_token(
    username,
    password,
    headless=True,
    remote_selenium="http://localhost:4444",
    wait=10,
    json_outfile="bing_cookie.json",
):
    options = webdriver.ChromeOptions()
    options.set_capability("goog:loggingPrefs", {"performance": "ALL"})

    if headless:
        options.add_argument("headless")  # Run browser in headless mode

    # Create a new WebDriver instance with Docker
    driver = webdriver.Remote(remote_selenium, options=options)

    # Open Bing
    driver.get("https://www.bing.com")

    # <button id="bnp_btn_accept" class="bnp_btn_accept">
    # respond to cookies
    try:
        cookie = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "bnp_btn_accept"))
        )
        cookie.click()
    except STimeout:
        pass

    try:
        login_button = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "id_l"))
        )
        login_button.click()

        username_field = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "i0116"))
        )
        username_field.send_keys(username)
        username_field.send_keys(Keys.ENTER)

        password_field = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "i0118"))
        )
        password_field.send_keys(password)
        password_field.send_keys(Keys.ENTER)

        signed_in_no = WebDriverWait(driver, wait).until(
            EC.element_to_be_clickable((By.ID, "idBtn_Back"))
        )
        signed_in_no.click()

        cookie = SimpleCookie()
        interesting = []
        # loop until some appropriate cookies are found
        while len(interesting) == 0:
            time.sleep(1)

            logs_raw = driver.get_log("performance")
            for r in logs_raw:
                try:
                    hdr = json.loads(r["message"])["message"]["params"][
                        "headers"
                    ]
                    if "cookie" in hdr.keys():
                        cookie.load(hdr["cookie"])
                        hdr["cookie"] = {
                            k: v.value for k, v in cookie.items()
                        }
                        if "_U" in hdr["cookie"].keys():
                            interesting.append(hdr)
                except KeyError:
                    pass

        if json_outfile is not None:
            with open("bing_cookie.json", "w") as f:
                json.dump(interesting, f, indent=2)

        return interesting[0]["cookie"]["_U"]
    except STimeout:
        return "selenium timeout"
    finally:
        # Close the WebDriver session
        driver.quit()

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

3 participants