From e83377d91206f7697cfef7bea6757f8222c8d910 Mon Sep 17 00:00:00 2001 From: Santiago Date: Wed, 26 Apr 2023 20:44:27 -0500 Subject: [PATCH] I changed the way headers are parameterized, I also removed a redundate cookie check and added a cookie existence check in the ChatGTP Class. This change fix cookie error in Google Account. --- utils/chatgpt.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/utils/chatgpt.py b/utils/chatgpt.py index f0189c4..8fb6bed 100644 --- a/utils/chatgpt.py +++ b/utils/chatgpt.py @@ -65,21 +65,18 @@ class ChatGPT: # self.cf_clearance = config.cf_clearance # self.session_token = config.session_token # conversation_id: message_id + if not "cookie" in vars(self.config): + raise Exception("Please update cookie in config/chatgpt_config.py") self.conversation_dict: Dict[str, Conversation] = {} - self.headers = dict( - { - # "cookie": f"cf_clearance={self.cf_clearance}; _puid={self._puid}; __Secure-next-auth.session-token={self.session_token}", - "cookie": self.config.cookie, - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36", - "accept": "*/*", + self.headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0', + 'Accept': '*/*', + "Cookie": self.config.cookie } - ) self.headers["authorization"] = self.get_authorization() def get_authorization(self): url = "https://chat.openai.com/api/auth/session" - if "cookie" in vars(self.config): - self.headers["cookie"] = self.config.cookie r = requests.get(url, headers=self.headers) authorization = r.json()["accessToken"] # authorization = self.config.accessToken