sydney.py: Exception: Failed to create conversation, received status: 404, Unclosed client session

when i use Sydney.py to easily create a CLI client for Bing Chat: example.py

import asyncio

from sydney import SydneyClient


async def main() -> None:
    async with SydneyClient() as sydney:
        while True:
            prompt = input("You: ")

            if prompt == "!reset":
                await sydney.reset_conversation()
                continue
            elif prompt == "!exit":
                break

            print("Sydney: ", end="", flush=True)
            async for response in sydney.ask_stream(prompt):
                print(response, end="", flush=True)
            print("\n")


if __name__ == "__main__":
    asyncio.run(main())

But it reported this error:

Traceback (most recent call last):
  File "~/Project/sydney.py/example.py", line 24, in <module>
    asyncio.run(main())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "~/Project/sydney.py/example.py", line 7, in main
    async with SydneyClient() as sydney:
  File "~/Project/sydney.py/sydney/sydney.py", line 57, in __aenter__
    await self.start_conversation()
  File "~/Project/sydney.py/sydney/sydney.py", line 259, in start_conversation
    raise Exception(
Exception: Failed to create conversation, received status: 404
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10a233bb0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x10aef11c0>, 0.491523)]']
connector: <aiohttp.connector.TCPConnector object at 0x10ae5ea00>

Is this a problem with Python 3.9?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

@vsakkas I apologize for the delayed response as I have been busy with a Vue project lately. I just noticed your merge and it seems to be working perfectly, just as we hoped for in this project.

Thank you for your contribution and for your patience.

Best regards

Thank you very much for letting me learn a lot about Python. Thank you again!

Yes, I was able to reproduce this issue sometimes on my local setup as well. I am not sure if it is related to the proxy support though, as it seems to be the behavior of input() in Python. You can see here a short discussion (and solution) about it: https://stackoverflow.com/questions/65976696/how-to-ignore-input-while-in-a-loop-python

So what seems to happens is that after this, Bing Chat closes the conversation from its side with the last message being: I'm sorry but I haven't received any message from you. If you have any questions or need help with anything, feel free to ask me anytime.🙂 but the Sydney Client tries to send another message to it anyways.

This script should fix the issue for you, I think:

import asyncio

from sydney import SydneyClient


def flush_input():
    try:
        import msvcrt

        while msvcrt.kbhit():
            msvcrt.getch()
    except ImportError:
        import sys, termios  # for linux/unix

        termios.tcflush(sys.stdin, termios.TCIOFLUSH)


async def main() -> None:
    async with SydneyClient() as sydney:
        while True:
            flush_input()
            prompt = input("You: ")
            await asyncio.sleep(0)

            if prompt == "!reset":
                await sydney.reset_conversation()
                continue
            if prompt == "!exit":
                break

            print("Sydney: ", end="", flush=True)
            async for response in sydney.ask_stream(prompt):
                print(response, end="", flush=True)


if __name__ == "__main__":
    asyncio.run(main())

According to my testing, if you type enter again while waiting for Sydney’s answer, it will prompt for the first time: You: Sydney: I'm sorry but I haven't received any message from you. If you have any questions or need help with anything, feel free to ask me anytime.🙂

The second time you ask again, he will report this error:

File "~/Project/sydney.py/sydney/sydney.py", line 349, in ask_stream
   async for response in self._ask(prompt, citations, raw, stream=True):
 File "~/Project/sydney.py/sydney/sydney.py", line 197, in _ask
   yield response["item"]["messages"][1]["text"]
IndexError: list index out of range

So if you wait for it to reply every time before entering, there won’t be any problems.

That’s great. I successfully used the latest branch.

(venv) ➜  sydney.py git:(feat/proxy-support) ✗ python example.py
You: When was Bing Chat released?
Sydney:
Microsoft announced the new Bing Chat on February 7th, 2023[^1^] and it was available to limited numbers of users since the launch date[^2^]. The Bing Chat preview was opened up to a wider audience in March 2023[^3^].

You: Sydney: I'm sorry but I haven't received a message from you. If you have any questions or need help with anything, feel free to ask me.🙂

You: love you~
Sydney: Traceback (most recent call last):
  File "~/Project/sydney.py/example.py", line 24, in <module>
    asyncio.run(main())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "~/Project/sydney.py/example.py", line 18, in main
    async for response in sydney.ask_stream(prompt):
  File "~/Project/sydney.py/sydney/sydney.py", line 349, in ask_stream
    async for response in self._ask(prompt, citations, raw, stream=True):
  File "~/Project/sydney.py/sydney/sydney.py", line 197, in _ask
    yield response["item"]["messages"][1]["text"]
IndexError: list index out of range

At that time, I replied with “love you”,She may be too shy to report the mistake ^-^

I have never heard of Poetry before and have always used Pip. It seems like it’s a good tool, and I will try to learn its usage.

It doesn’t seem to be working

(venv) ➜  sydney.py git:(feat/proxy-support) ✗ echo $https_proxy
http://127.0.0.1:7890
(venv) ➜  sydney.py git:(feat/proxy-support) ✗ echo $http_proxy
http://127.0.0.1:7890
(venv) ➜  sydney.py git:(feat/proxy-support) ✗
(venv) ➜  sydney.py git:(feat/proxy-support) ✗ curl -I https://www.bing.com/turing/conversation/create
HTTP/1.1 200 Connection established

HTTP/2 200
content-length: 0
x-cache: CONFIG_NOCACHE
accept-ch: Sec-CH-UA-Arch, Sec-CH-UA-Bitness, Sec-CH-UA-Full-Version, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version
x-msedge-ref: Ref A: DF1BFEF4A7494C89B6270784203D9DFA Ref B: SG1EDGE0309 Ref C: 2023-04-20T10:12:45Z
date: Thu, 20 Apr 2023 10:12:44 GMT

(venv) ➜  sydney.py git:(feat/proxy-support) ✗ echo $BING_U_COOKIE
14eEpGSiqV7NFTxgpARz6nPSc79WHnFDW_swzTL7vZlCkG0TOW5-ATF1MU2DvzELgTVoSyE2voXBkBa2gPe9dHBIaTyfUK5-Z__W4CDq9EeOtRl7KAMzvEN4D5LM078mbTTkBXkbCkCsCdkIiD5whxyu8nQUJvi26laGFP_b5jdzBm4wG4n62_FHHuB-xCJYNzRDGpudog6x0Izb1z7D-tREiRNR8upT-znN0teVaLHM

(venv) ➜  sydney.py git:(feat/proxy-support) ✗ python example.py
Traceback (most recent call last):
  File "~/Project/sydney.py/example.py", line 24, in <module>
    asyncio.run(main())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "~/Project/sydney.py/example.py", line 7, in main
    async with SydneyClient() as sydney:
  File "~/Project/sydney.py/sydney/sydney.py", line 64, in __aenter__
    await self.start_conversation()
  File "~/Project/sydney.py/sydney/sydney.py", line 272, in start_conversation
    raise Exception(
Exception: Failed to create conversation, received status: 404
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10e51d1f0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x10ef5a220>, 2.972278958)]']
connector: <aiohttp.connector.TCPConnector object at 0x10ef390d0>