You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 515d5c4
Browse filesBrowse the repository at this point in the historyBrowse files
fix(http-clients): Map proxy errors in stream() to ProxyError (#2529)
### Description
- `HttpxHttpClient.stream()` and `ImpitHttpClient.stream()` only mapped
timeouts, so a proxy failure escaped as `httpx2.ProxyError` or
`impit.ProxyError`. They now map it to `crawlee.errors.ProxyError` with
the same `_is_proxy_error` check that `crawl()` and `send_request()` of
each client use, and that `CurlImpersonateHttpClient.stream()` already
follows. `HttpClient.stream()` already documents this error.
- In all three clients, the `ProxyError` from `stream()` carries the
message of the library error, so the sitemap retry warning shows the
cause (for example `403 Forbidden`).
- `ProxyError` is a `SessionError`, so
`FileDownloadCrawler(stream=True)` now rotates the session on a bad
proxy instead of spending a request retry.
- Adds `test_stream_with_proxy_disabled`, next to the existing `crawl`
and `send_request` versions. It also checks that the error has a
message.
Behavior change: a proxy failure in `stream()` of the httpx and impit
clients is now a `ProxyError` (a `SessionError`), not the library's own
exception. Code that caught `httpx2.ProxyError` or `impit.ProxyError`
around `stream()` needs to catch `crawlee.errors.ProxyError`.
### Issues
- Closes: #2528
### Testing
- `pytest tests/unit/http_clients`: 17 passed. `pytest
tests/integration/http_clients/test_http_clients.py -k "stream or
proxy"` on Windows 11, Python 3.14: 30 passed, 18 skipped (the proxy
tests are skipped on Windows by the existing marker).
- With the skip marker of `test_stream_with_proxy_disabled` removed
locally: 3 passed (httpx, impit, curl). With only the source change
reverted: 2 failed (httpx, impit), curl passed.
- Compared `crawl`, `send_request` and `stream` for 276 generated errors
(httpx2 and impit exception classes, plus `RuntimeError`, `OSError` and
`CancelledError`, crossed with 12 messages that include the
`ROTATE_PROXY_ERRORS` needles). Before: 88 disagreements. After: 0.
Timeouts, connect and read errors, other transport errors and
non-transport errors still come out as before.
- `FileDownloadCrawler(stream=True)` with a proxy that answers `CONNECT`
with 403: before, `httpx2.ProxyError` / `impit.ProxyError`,
`retry_count=2`, no session rotation. After,
`crawlee.errors.ProxyError`, `retry_count=0`, 2 session rotations.
- `ruff check`, `ruff format --check` and `ty check
src/crawlee/http_clients` pass.
### Checklist
- [x] CI passed
Validated with Claude Opus 5.5.
---------
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
0 commit comments