Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
fix server rejected WebSocket connection: HTTP 200 error
Browse files Browse the repository at this point in the history
  • Loading branch information
xnny authored and brainboost committed Jul 24, 2023
1 parent 47951af commit d9898b1
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/EdgeGPT/chathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
import os
import ssl
import sys
import aiohttp
from time import time
from typing import Generator
from typing import List
from typing import Union
from typing import Generator, List, Union

import aiohttp
import certifi
import httpx
from BingImageCreator import ImageGenAsync

from .constants import DELIMITER
from .constants import HEADERS
from .constants import HEADERS_INIT_CONVER
from .constants import DELIMITER, HEADERS, HEADERS_INIT_CONVER
from .conversation import Conversation
from .conversation_style import CONVERSATION_STYLE_TYPE
from .request import ChatHubRequest
from .utilities import append_identifier
from .utilities import get_ran_hex
from .utilities import guess_locale
from .utilities import append_identifier, get_ran_hex, guess_locale

ssl_context = ssl.create_default_context()
ssl_context.load_verify_locations(certifi.where())
Expand Down Expand Up @@ -103,9 +97,20 @@ async def ask_stream(
) -> Generator[bool, Union[dict, str], None]:
""" """

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),
})

# Check if websocket is closed
async with self.aio_session.ws_connect(
wss_link or "wss://sydney.bing.com/sydney/ChatHub",
extra_headers=req_header,
max_size=None,
ssl=ssl_context,
headers=HEADERS,
proxy=self.proxy,
Expand Down

0 comments on commit d9898b1

Please sign in to comment.