From 91cee2eaa82ef92ebb1a43d8883870f7bcde0a53 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Thu, 12 Sep 2024 11:36:47 -0700 Subject: [PATCH] Handle redirects when scheduling chats from automations --- src/khoj/routers/helpers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index d7a05f8a..537d92a8 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1223,7 +1223,13 @@ def scheduled_chat( logger.info(f"Payload: {json_payload}") # Call the chat API endpoint with authenticated user token and query - raw_response = requests.post(url, headers=headers, json=json_payload) + raw_response = requests.post(url, headers=headers, json=json_payload, allow_redirects=False) + + # Handle redirect manually if necessary + if raw_response.status_code in [301, 302]: + redirect_url = raw_response.headers["Location"] + logger.info(f"Redirecting to {redirect_url}") + raw_response = requests.post(redirect_url, headers=headers, json=json_payload) # Log response details logger.info(f"Response status code: {raw_response.status_code}")