sydney.py icon indicating copy to clipboard operation
sydney.py copied to clipboard

Failed to connect to Copilot, connection timed out

Open Mazawrath opened this issue 1 year ago • 13 comments

Apologizes for the rather non-helpful error, I saw someone else had issues with this same error but I just can't seem to figure out what it is.

Traceback (most recent call last):
  File "/root/workspace/ChatGPT_API/src/bingGPT.py", line 52, in ask
    request = await sydney.ask(ask_request.prompt, attachment=ask_request.attachment, raw=True)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/sydney/sydney.py", line 515, in ask
    async for response, suggested_responses in self._ask(
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/sydney/sydney.py", line 348, in _ask
    raise ConnectionTimeoutException(
sydney.exceptions.ConnectionTimeoutException: Failed to connect to Copilot, connection timed out

If I remove the BING_COOKIES, I get this error instead

Traceback (most recent call last):
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 274, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/src/bingGPT.py", line 37, in ask
    await sydney.reset_conversation(style="creative")
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/sydney/sydney.py", line 748, in reset_conversation
    await self.start_conversation()
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/sydney/sydney.py", line 462, in start_conversation
    response_dict = await response.json()
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/root/workspace/ChatGPT_API/.venv/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1165, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://www.bing.com/turing/conversation/create?bundleVersion=1.1342.3-cplt.7')

Mazawrath avatar Dec 15 '23 07:12 Mazawrath

Thanks @Mazawrath for reporting this

I will have a look, I think this does show up sometimes and typically waiting and retrying should do the trick. I will see if I can do something about this

vsakkas avatar Dec 15 '23 21:12 vsakkas

Yeah unfortunately for me it's 100% consistent and happens every time I am running a much older version on this project my other VM and this issue doesn't happen on that one, so not sure what the difference is.

Mazawrath avatar Dec 15 '23 23:12 Mazawrath

I was able to do further testing. I tried wscat -c wss://sydney.bing.com/sydney/ChatHub to see if the WebSocket responds and got error: Unexpected server response: 200 This is happening on my DigitalOcean VM, when I was originally using Azure.

Is there anything that can be done to fix this?

Mazawrath avatar Dec 19 '23 03:12 Mazawrath

Yeah unfortunately for me it's 100% consistent and happens every time I am running a much older version on this project my other VM and this issue doesn't happen on that one, so not sure what the difference is.

Hi @Mazawrath Which version are you using that does not have this issue? If that's the case, there's probably a regression

vsakkas avatar Dec 22 '23 14:12 vsakkas

Latest version 0.20.1 could possibly fix this due to improvements in the API compatibility.

vsakkas avatar Jan 01 '24 18:01 vsakkas

@vsakkas I still get the same error on AWS server. It's working fine on computer but not on my AWS server. I will try to use a VPN to see if it's not related to a blacklist of datacenter IPs.

IKDH avatar Jan 01 '24 23:01 IKDH

Yeah unfortunately for me it's 100% consistent and happens every time I am running a much older version on this project my other VM and this issue doesn't happen on that one, so not sure what the difference is.

@Mazawrath Could you tell me which version of this lib is working on your VM ? Is it with or without cookies ? Because all my tests failed on datacenter.

IKDH avatar Jan 05 '24 11:01 IKDH

I can also confirm going from DigitalOcean to Oracle Cloud didn't fix it either. Seems like Bing is blacklisting IPs from both of those services.

The only service I've actually managed to use that works is Azure.

Mazawrath avatar Jan 06 '24 21:01 Mazawrath

I can also confirm going from DigitalOcean to Oracle Cloud didn't fix it either. Seems like Bing is blacklisting IPs from both of those services.

The only service I've actually managed to use that works is Azure.

I am not sure if it's related because even with residential proxy, I can't use the script on datacenter. Which version of the lib is working on Azure ?

IKDH avatar Jan 07 '24 00:01 IKDH

It is working on Namecheap VPS @vsakkas @Mazawrath @IKDH I've noticed that my Digital Ocean droplet running Ubuntu 22 can't connect to Bing Chat, while my Namecheap VPS running the same OS can. It seems Bing might blacklist certain IP ranges.

To check if your server can connect to Bing Chat, use this command: curl https://edgeservices.bing.com/edgesvc/turing/conversation/create?bundleVersion=1.1381.12

If you get a JSON response like: {"conversationId":"_something_","clientId":"_something_","result":{"value":"Success","message":null}}

then your server is good to go for running sydney.py. This is a quick way to verify connectivity before proceeding with your setup. If the response is empty, it's possible that your server may not allow connecting to Bing Chat

Hope this helps!

haiht24 avatar Jan 13 '24 03:01 haiht24

So, I went down quite the rabbithole. First of all, thank you for @haiht24 for confirming what I assumed was true, that yes, Bing is blocking Oracle Cloud. Now, I was able to get around this with a proxy. However, sydney.py uses websockets, which does not support proxies. I was able to get a proxy setup using websocket-client, and was able to string together a successful solution, however it doesn't seem to be async and might have issues if it gets implemented here. Worth looking into @vsakkas of maybe finding a way to support proxies for the actual websocket part, I didn't find the issue to be with aiohttp, so that use_proxy argument did not fix my issue.

Mazawrath avatar Jan 15 '24 07:01 Mazawrath

Thank you @haiht24 @Mazawrath for the investigation!

I've been somewhat busy lately, so development has slowed down in the last couple of weeks, but this is definitely something that I'd like to tackle wherever I have the time for it.

I will look int some websocket alternatives or maybe even a way to add proxy support without replacing the current library. Will follow up once I have something ready!

vsakkas avatar Jan 15 '24 19:01 vsakkas

I've been using sydney since a month, but then it started to require captcha consistently. Now I'm going through either one of these 4 errors every time I try to enable cookie or proxy or use sydney without them:

sydney.exceptions.CreateConversationException: Failed to create conversation, received status: 500

sydney.exceptions.ConnectionTimeoutException: Failed to connect to Copilot, connection timed out

sydney.exceptions.NoResponseException: No response was returned

aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://copilot.microsoft.com/turing/conversation/create?bundleVersion=1.1729.0')       

What I found has helped so far was only switching to a different machine and network.

I carefully followed recommendations to enable cookies but couldn't set them to work, any time I tried I got one of the above errors. I didn't get any "Verified" message, although I was logged in (tried "guest" as well) and talked through multiple conversations till they reached the quota. Adding optional cookie didn't make any difference: os.environ["BING_U_COOKIE"] = 'OPTIONAL'

nisnevich avatar May 24 '24 04:05 nisnevich