Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(python-sdk): raise transport errors from search instead of an AttributeError (#5248)

Erik Engervallca571342b3b5
diff --git a/apps/python-sdk/firecrawl/__init__.py b/apps/python-sdk/firecrawl/__init__.py
index 5c559d264..828810d77 100644
--- a/apps/python-sdk/firecrawl/__init__.py
+++ b/apps/python-sdk/firecrawl/__init__.py
@@ -42,7 +42,7 @@ from .v1 import (
V1ChangeTrackingOptions,
)
-__version__ = "4.53.1"
+__version__ = "4.53.2"
# Define the logger for the Firecrawl project
logger: logging.Logger = logging.getLogger("firecrawl")
diff --git a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_response.py b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_response.py
index 6ca2858ca..00b85cc4d 100644
--- a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_response.py
+++ b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_search_response.py
@@ -61,3 +61,25 @@ class TestSearchDeveloperResults:
assert isinstance(result.web[0], SearchResultWeb)
assert result.web[0].category == "developer"
assert not hasattr(result, "developer")
+
+class TestSearchTransportErrors:
+ """A transport error without a response is raised as itself, not as an AttributeError."""
+
+ def test_sync_timeout_is_reraised(self):
+ import requests
+
+ client = Mock()
+ client.post.side_effect = requests.exceptions.ReadTimeout("read timed out")
+
+ with pytest.raises(requests.exceptions.ReadTimeout):
+ search(client, SearchRequest(query="test"))
+
+ @pytest.mark.asyncio
+ async def test_async_timeout_is_reraised(self):
+ import httpx
+
+ client = Mock()
+ client.post = AsyncMock(side_effect=httpx.ReadTimeout("read timed out"))
+
+ with pytest.raises(httpx.ReadTimeout):
+ await search_async(client, SearchRequest(query="test"))
diff --git a/apps/python-sdk/firecrawl/v2/methods/aio/search.py b/apps/python-sdk/firecrawl/v2/methods/aio/search.py
index a45aa96b0..28c41735d 100644
--- a/apps/python-sdk/firecrawl/v2/methods/aio/search.py
+++ b/apps/python-sdk/firecrawl/v2/methods/aio/search.py
@@ -53,8 +53,9 @@ async def search(
out.tools = [DiscoveredTool(**item) for item in data["tools"]]
return out
except Exception as err:
- if hasattr(err, "response"):
- handle_response_error(getattr(err, "response"), "search")
+ response = getattr(err, "response", None)
+ if response is not None:
+ handle_response_error(response, "search")
raise err
def _transform_array(arr: List[Any], result_type: Type[T]) -> List[Union[T, Document]]:
diff --git a/apps/python-sdk/firecrawl/v2/methods/search.py b/apps/python-sdk/firecrawl/v2/methods/search.py
index 0cb884863..10fe30c7f 100644
--- a/apps/python-sdk/firecrawl/v2/methods/search.py
+++ b/apps/python-sdk/firecrawl/v2/methods/search.py
@@ -47,10 +47,9 @@ def search(
out.tools = [DiscoveredTool(**item) for item in data["tools"]]
return out
except Exception as err:
- # If the error is an HTTP error from requests, handle it
- # (simulate isAxiosError by checking for requests' HTTPError or Response)
- if hasattr(err, "response"):
- handle_response_error(getattr(err, "response"), "search")
+ response = getattr(err, "response", None)
+ if response is not None:
+ handle_response_error(response, "search")
raise err
def _transform_array(arr: List[Any], result_type: Type[T]) -> List[Union[T, 'Document']]: