acheong08/EdgeGPT

[Feature Request]: websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200

fenglilinglegeluan opened this issue · 22 comments

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

问题:
File "D:\software\python\Lib\site-packages\EdgeGPT\EdgeGPT.py", line 116, in ask async for final, response in self.chat_hub.ask_stream( File "D:\software\python\Lib\site-packages\EdgeGPT\chathub.py", line 103, in ask_stream async with websockets.connect( File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 637, in __aenter__ return await self File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 655, in __await_impl_timeout__ return await self.__await_impl__() File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 662, in __await_impl__ await protocol.handshake( File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 329, in handshake raise InvalidStatusCode(status_code, response_headers) websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200
愁死了
卡在chathub.py的ask_stream方法中的103行代码:
async with websockets.connect( wss_link or "wss://sydney.bing.com/sydney/ChatHub", extra_headers=HEADERS, max_size=None, ssl=ssl_context, ping_interval=None, ) as wss:
websockets connect连接的时候出现的问题。正常网页访问的时候没问题,请求大佬指点一下。

Proposed workflow

1.尝试换了代理
2.尝试修改请求头
3.还是没有成功

Additional information

No response

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

问题: File "D:\software\python\Lib\site-packages\EdgeGPT\EdgeGPT.py", line 116, in ask async for final, response in self.chat_hub.ask_stream( File "D:\software\python\Lib\site-packages\EdgeGPT\chathub.py", line 103, in ask_stream async with websockets.connect( File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 637, in __aenter__ return await self File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 655, in __await_impl_timeout__ return await self.__await_impl__() File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 662, in __await_impl__ await protocol.handshake( File "D:\software\python\Lib\site-packages\websockets\legacy\client.py", line 329, in handshake raise InvalidStatusCode(status_code, response_headers) websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200 愁死了 卡在chathub.py的ask_stream方法中的103行代码: async with websockets.connect( wss_link or "wss://sydney.bing.com/sydney/ChatHub", extra_headers=HEADERS, max_size=None, ssl=ssl_context, ping_interval=None, ) as wss: websockets connect连接的时候出现的问题。正常网页访问的时候没问题,请求大佬指点一下。

Proposed workflow

1.尝试换了代理 2.尝试修改请求头 3.还是没有成功

Additional information

No response

一样,就在今天.....新版和老版都出现这个问题了

same error

我也是

+1

kkroid commented

same error here

ArtPei commented

遇到了一样的问题,希望有高手能拯救

猜测是这里,但是我不会改:
Cipher Suites Length: 32
Cipher Suites (16 suites)
Cipher Suite: Reserved (GREASE) (0x6a6a)
Cipher Suite: TLS_AES_128_GCM_SHA256 (0x1301)
Cipher Suite: TLS_AES_256_GCM_SHA384 (0x1302)
Cipher Suite: TLS_CHACHA20_POLY1305_SHA256 (0x1303)
Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xc02b)
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f)
Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (0xc02c)
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)
Cipher Suite: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca9)
Cipher Suite: TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca8)
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (0xc013)
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (0xc014)
Cipher Suite: TLS_RSA_WITH_AES_128_GCM_SHA256 (0x009c)
Cipher Suite: TLS_RSA_WITH_AES_256_GCM_SHA384 (0x009d)
Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA (0x002f)
Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA (0x0035)

我知道为什么了,在0.11.1的更新中chathup.py中原本发起ws请求的地方是使用了代理的
image
修改之后没有了
image
所以现在想正常用的话必须得配置系统的全局代理才行,或者等作者修复吧

image
在我启动了clash的tun模式后发现这个ws连接走的是虚拟网卡,说明在代码里配置的代理确实是没有生效的。。。

Proxy support was removed to migrate away from aiohttp due to #553

https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16 still uses aiohttp but requires some patching

same problem ...
I didn't dive into the problem yet... but pretty sure that a thing like "from curl_cffi import requests" could bypass this trouble ... (using curl_cffi.requests in place of aiohttp) : this package can impersonate browsers' TLS signatures or JA3 fingerprints. If you are blocked by some website for no obvious reason, you can give this package a try.

@acheong08 pretty sure that it's the time to migrate edgegpt/bingimagecreator on https://github.com/yifeikong/curl_cffi ...
to avoid impersonate trouble ... see more here : https://www.fastly.com/blog/a-first-look-at-chromes-tls-clienthello-permutation-in-the-wild
With thins kind of lib ... http server can't detect if the request come from a real chrome browser, or a python app trying to requests http

My PR, on a clone of g4f (with bing provider), make it works in my context (my french hosting provider) ... (using curl_cffi.requests instead of the basic requests)

@manatlan this looks like a different issue.

The websockets error comes from https://pypi.org/project/websockets/ which isn't well maintained.

This error seems to be China specific

It could be fixed via proxychains

@SoraRoseous 我开了全局代理也不行。

是的,**必须使用vpn才能访问bing,可能导致了这个问题发生。我一会把提到的解决方法都去试试。

kkroid commented

It could be fixed via proxychains

It works

yea it works with proxychains

https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16 still uses aiohttp but requires some patching

I use this version of EdageGPT. Now it's finally working !!! thank you all !!!

使用clash 0.19.1版本试试,我用最新版的tun也不行,降到这个0.19.1版本,tun就好使了

The version 0.10.16 of the EdgeGPT library, available at https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16, is no longer working. Could you please suggest a fork or an alternative library?