From 1b81a7c755abfce5e8108877e7f2053d22bf44d3 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Thu, 22 May 2025 16:46:01 +0100 Subject: [PATCH] fix(blocks): Error messages from SendWebRequestBlock use the requested translated IP instead of the orignal URL (#10009) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Changes 🏗️ Keep the original URL when an HTTP error occurs in `SendWebRequestBlock`. ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Test sending POST request on a web that doesn't support POST request using `SendWebRequestBlock`. --- autogpt_platform/backend/backend/util/request.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autogpt_platform/backend/backend/util/request.py b/autogpt_platform/backend/backend/util/request.py index 9086e779c6..4dfd32a12a 100644 --- a/autogpt_platform/backend/backend/util/request.py +++ b/autogpt_platform/backend/backend/util/request.py @@ -247,6 +247,7 @@ class Requests: # Pin the URL if untrusted hostname = url.hostname + original_url = url.geturl() if not is_trusted: url = pin_url(url, ip_addresses) @@ -277,6 +278,12 @@ class Requests: **kwargs, ) + # Replace response URLs with the original host for clearer error messages + if url.hostname != hostname: + response.url = original_url + if response.request is not None: + response.request.url = original_url + if self.raise_for_status: response.raise_for_status()