From 0c8c539e9b6e683aa851cc57798fa6ca30eb0b99 Mon Sep 17 00:00:00 2001 From: QQisQQ <40739351+QQisQQ@users.noreply.github.com> Date: Wed, 19 Jul 2023 04:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3new=20bing=20=E6=8A=A5?= =?UTF-8?q?=E9=94=99200=20(fix=20new=20bing=20error=20code=20200=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit modify from https://github.com/acheong08/EdgeGPT/pull/610/commits/16e00af9d55e1e32c4389512b02cac1c7eca4672 works for my issue: ``` Traceback (most recent call last): File "./request_llm/bridge_newbingfree.py", line 152, in run asyncio.run(self.async_run()) File "/root/miniconda3/envs/py311/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/root/miniconda3/envs/py311/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/envs/py311/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "./request_llm/bridge_newbingfree.py", line 98, in async_run async for final, response in self.newbing_model.ask_stream( File "./request_llm/edge_gpt_free.py", line 676, in ask_stream async for response in self.chat_hub.ask_stream( File "./request_llm/edge_gpt_free.py", line 456, in ask_stream self.wss = await self.session.ws_connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/envs/py311/lib/python3.11/site-packages/aiohttp/client.py", line 795, in _ws_connect raise WSServerHandshakeError( aiohttp.client_exceptions.WSServerHandshakeError: 200, message='Invalid response status', url=URL('wss://sydney.bing.com/sydney/ChatHub') ``` --- request_llm/edge_gpt_free.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/request_llm/edge_gpt_free.py b/request_llm/edge_gpt_free.py index ef61873..1e96df0 100644 --- a/request_llm/edge_gpt_free.py +++ b/request_llm/edge_gpt_free.py @@ -447,6 +447,15 @@ class _ChatHub: """ Ask a question to the bot """ + req_header = HEADERS + if self.cookies is not None: + ws_cookies = [] + for cookie in self.cookies: + ws_cookies.append(f"{cookie['name']}={cookie['value']}") + req_header.update({ + 'Cookie': ';'.join(ws_cookies), + }) + timeout = aiohttp.ClientTimeout(total=30) self.session = aiohttp.ClientSession(timeout=timeout) @@ -455,7 +464,7 @@ class _ChatHub: # Check if websocket is closed self.wss = await self.session.ws_connect( wss_link, - headers=HEADERS, + headers=req_header, ssl=ssl_context, proxy=self.proxy, autoping=False, @@ -1109,4 +1118,4 @@ class ImageQuery(Query): if __name__ == "__main__": - main() \ No newline at end of file + main()