File size: 1,905 Bytes
f05e49d
21f117b
70c1e23
dd37946
855fab6
70c1e23
c05a7fe
 
 
 
 
21f117b
70c1e23
c05a7fe
 
70c1e23
 
 
 
c05a7fe
a1801ab
 
 
855fab6
a1801ab
dd37946
21f117b
a1801ab
1f691c1
f05e49d
c05a7fe
a1801ab
f05e49d
70c1e23
c05a7fe
3eecc54
f05e49d
3eecc54
f05e49d
3eecc54
 
 
f05e49d
 
21f117b
 
 
 
 
f05e49d
 
c05a7fe
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import requests
from pprint import pprint
from utils.logger import logger
from utils.enver import enver
from networks import ConversationCreateHeadersConstructor
from networks import CookiesConstructor


class ConversationCreator:
    conversation_create_url = "https://www.bing.com/turing/conversation/create"

    def __init__(self, cookies: dict = {}):
        self.request_cookies = cookies

    def construct_cookies(self):
        cookies_constructor = CookiesConstructor()
        if not self.request_cookies:
            cookies_constructor.construct()
            self.request_cookies = cookies_constructor.cookies

    def construct_headers(self):
        # New Bing 封锁原理探讨 #78
        # https://github.com/weaigc/bingo/issues/78
        self.request_headers = ConversationCreateHeadersConstructor().request_headers

    def create(self):
        self.construct_cookies()
        self.construct_headers()
        enver.set_envs(proxies=True)
        self.response = requests.get(
            self.conversation_create_url,
            headers=self.request_headers,
            proxies=enver.requests_proxies,
            cookies=self.request_cookies,
        )
        try:
            self.response_data = self.response.json()
        except:
            print(self.response.text)
            raise Exception(
                f"x Failed to create conversation: {self.response.status_code}"
            )
        self.response_headers = self.response.headers
        pprint(self.response_data)

        # These info would be used in ConversationConnector
        self.sec_access_token = self.response_headers[
            "x-sydney-encryptedconversationsignature"
        ]
        self.client_id = self.response_data["clientId"]
        self.conversation_id = self.response_data["conversationId"]


if __name__ == "__main__":
    creator = ConversationCreator()
    creator.create()