vsakkas / sydney.py

Python Client for Copilot (formerly named Bing Chat), also known as Sydney.
MIT License
239 stars 31 forks source link

Getting server rejected WebSocket connection: HTTP 200 on Linux while it works on Windows #70

Closed eforce67 closed 2 months ago

eforce67 commented 8 months ago

Hello, I have been using your library to retrieve responses from Bing's chat. And your library was successful on Windows 10 without any errors. However, when using the same script I ran on Windows, it gave me the following error. Any ideas on what may be going on?

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/client.py", line 662, in __await_impl__
    await protocol.handshake(
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/client.py", line 329, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/client.py", line 655, in __await_impl_timeout__
    return await self.__await_impl__()
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/client.py", line 676, in __await_impl__
    await protocol.wait_closed()
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/AI_workspace/summarizer.py", line 294, in <module>
    asyncio.run(summarize())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/root/AI_workspace/summarizer.py", line 291, in summarize
    await bot.create_bot(prompts=prompts, template=template, conversation_mode=conversation_mode)
  File "/root/AI_workspace/summarizer.py", line 208, in create_bot
    return await self.run(instance=bot_result,
  File "/root/AI_workspace/summarizer.py", line 223, in run
    response = await sydney.compose(f'{template}\n\nPROMPT: {prompt}' if template else prompt, raw=True)
  File "/usr/local/lib/python3.10/dist-packages/sydney/sydney.py", line 509, in compose
    async for response in self._compose(
  File "/usr/local/lib/python3.10/dist-packages/sydney/sydney.py", line 280, in _compose
    self.wss_client = await websockets.connect(
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/client.py", line 654, in __await_impl_timeout__
    async with asyncio_timeout(self.open_timeout):
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/async_timeout.py", line 169, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/async_timeout.py", line 252, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
vsakkas commented 8 months ago

Hi @eforce67

I'll have a look into this. However, I do not think that this is related to using Linux as I develop the library on Linux without any issues (usually). Have you tried getting a fresh cookie for your Linux sessions? Also, I've sometimes experienced this error when running the test suite and usually waiting and rerunning seems to fix the issue.

eforce67 commented 8 months ago

Hey @vsakkas , I didn't try out cookies because my goal was to get responses from BingChat with many proxies. And so far while running my code many times, I have not yet achieved a state where the code randomly runs despite previous failure.

However all this works fine on windows 10. I'm going to see if it works on a different server although.

Eikosa commented 8 months ago

Unfortunately it doesn't work for me in Ubuntu - 22.04 either due to the same error

vsakkas commented 8 months ago

This is challenging to debug, because I cannot reproduce this issue on my Linux machine. Problem is, I cannot use the library without cookies, possibly due to being in a different region, so it's harder to replicate the setup that introduces this issue.

I've released v0.16.1 which uses additional headers when creating a connection to Bing Chat, including the Origin header. It might help with the current issue, although that's not guaranteed.

Other ideas that come to mind are: 1) Wait and rerun. 2) Try a different server. 3) Try a different proxy or check your proxy configuration.

I will let you know if I come up with anything better!

abinjob commented 8 months ago

Made the same error

katanhich commented 8 months ago

Hi @vsakkas , I am encountering the same error. It works on my laptop (Windows 10 and Ubuntu), but it does not work on the AWS EC2 instance in the Oregon region.

IKDH commented 7 months ago

@vsakkas is it working for you on linux server ?

vsakkas commented 7 months ago

@vsakkas is it working for you on linux server ?

Hi @IKDH Yes, I do all the development and testing on Linux, haven't encountered any consistent websocket issues. I will see if I can reproduce this issue though

IKDH commented 7 months ago

Thank you for you answer ! Linux on a computer or on a server like AWS ?

haiht24 commented 5 months ago

Hope this help

mizrits commented 4 months ago

Hope this help

thank you for the advice. Succeeded!