Antonio Cheong
commited on
Commit
·
b25c140
1
Parent(s):
2292b84
Use TLS client
Browse files- src/EdgeGPT.py +51 -49
src/EdgeGPT.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
import sys
|
9 |
|
10 |
import requests
|
|
|
11 |
import websockets.client as websockets
|
12 |
|
13 |
DELIMITER = "\x1e"
|
@@ -104,56 +105,57 @@ class Conversation:
|
|
104 |
"conversationSignature": None,
|
105 |
"result": {"value": "Success", "message": None},
|
106 |
}
|
|
|
107 |
# POST request to get token
|
108 |
# Create cookies
|
109 |
-
if os.environ.get("BING_U") is None:
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
else:
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
try:
|
158 |
self.struct = response.json()
|
159 |
if self.struct["result"]["value"] == "UnauthorizedRequest":
|
@@ -350,7 +352,7 @@ if __name__ == "__main__":
|
|
350 |
parser = argparse.ArgumentParser()
|
351 |
parser.add_argument("--no-stream", action="store_true")
|
352 |
parser.add_argument("--bing-cookie", type=str, default="", required=True)
|
353 |
-
parser.add_argument("--kiev-cookie", type=str, default="", required=
|
354 |
args = parser.parse_args()
|
355 |
if args.bing_cookie:
|
356 |
os.environ["BING_U"] = args.bing_cookie
|
|
|
8 |
import sys
|
9 |
|
10 |
import requests
|
11 |
+
import tls_client
|
12 |
import websockets.client as websockets
|
13 |
|
14 |
DELIMITER = "\x1e"
|
|
|
105 |
"conversationSignature": None,
|
106 |
"result": {"value": "Success", "message": None},
|
107 |
}
|
108 |
+
self.session = tls_client.Session(client_identifier="chrome_108")
|
109 |
# POST request to get token
|
110 |
# Create cookies
|
111 |
+
# if os.environ.get("BING_U") is None:
|
112 |
+
# home = os.path.expanduser("~")
|
113 |
+
# # Check if token exists
|
114 |
+
# token_path = f"{home}/.config/bing_token"
|
115 |
+
# # Make .config directory if it doesn't exist
|
116 |
+
# if not os.path.exists(f"{home}/.config"):
|
117 |
+
# os.mkdir(f"{home}/.config")
|
118 |
+
# if os.path.exists(token_path):
|
119 |
+
# with open(token_path, "r", encoding="utf-8") as file:
|
120 |
+
# token = file.read()
|
121 |
+
# else:
|
122 |
+
# url = "https://images.duti.tech/allow"
|
123 |
+
# response = requests.post(
|
124 |
+
# url,
|
125 |
+
# timeout=10,
|
126 |
+
# headers=headers,
|
127 |
+
# )
|
128 |
+
# if response.status_code != 200:
|
129 |
+
# raise Exception("Authentication failed")
|
130 |
+
# token = response.json()["token"]
|
131 |
+
# # Save token
|
132 |
+
# with open(token_path, "w", encoding="utf-8") as file:
|
133 |
+
# file.write(token)
|
134 |
+
# url = "https://images.duti.tech/auth"
|
135 |
+
# # Send GET request
|
136 |
+
# response = requests.get(
|
137 |
+
# url,
|
138 |
+
# headers=headers,
|
139 |
+
# timeout=10,
|
140 |
+
# )
|
141 |
+
# if response.status_code != 200:
|
142 |
+
# raise Exception("Authentication failed")
|
143 |
+
|
144 |
+
# else:
|
145 |
+
cookies = {
|
146 |
+
"_U": os.environ.get("BING_U"),
|
147 |
+
"KievRPSSecAuth": os.environ.get("KIEV_U"),
|
148 |
+
}
|
149 |
+
url = "https://www.bing.com/turing/conversation/create"
|
150 |
+
# Send GET request
|
151 |
+
response = self.session.get(
|
152 |
+
url,
|
153 |
+
cookies=cookies,
|
154 |
+
timeout_seconds=30,
|
155 |
+
headers=headers,
|
156 |
+
)
|
157 |
+
if response.status_code != 200:
|
158 |
+
raise Exception("Authentication failed")
|
159 |
try:
|
160 |
self.struct = response.json()
|
161 |
if self.struct["result"]["value"] == "UnauthorizedRequest":
|
|
|
352 |
parser = argparse.ArgumentParser()
|
353 |
parser.add_argument("--no-stream", action="store_true")
|
354 |
parser.add_argument("--bing-cookie", type=str, default="", required=True)
|
355 |
+
parser.add_argument("--kiev-cookie", type=str, default="", required=False)
|
356 |
args = parser.parse_args()
|
357 |
if args.bing_cookie:
|
358 |
os.environ["BING_U"] = args.bing_cookie
|