MCPcopy Create free account
hub / github.com/apify/crawlee-python / stream

Method stream

src/crawlee/http_clients/_httpx.py:223–256  ·  view source on GitHub ↗
(
        self,
        url: str,
        *,
        method: HttpMethod = 'GET',
        headers: HttpHeaders | dict[str, str] | None = None,
        payload: HttpPayload | None = None,
        session: Session | None = None,
        proxy_info: ProxyInfo | None = None,
        timeout: timedelta | None = None,
    )

Source from the content-addressed store, hash-verified

221 @asynccontextmanager
222 @override
223 async def stream(
224 self,
225 url: str,
226 *,
227 method: HttpMethod = 'GET',
228 headers: HttpHeaders | dict[str, str] | None = None,
229 payload: HttpPayload | None = None,
230 session: Session | None = None,
231 proxy_info: ProxyInfo | None = None,
232 timeout: timedelta | None = None,
233 ) -> AsyncGenerator[HttpResponse]:
234 validate_http_url(url)
235
236 client = self._get_client(proxy_info.url if proxy_info else None)
237
238 http_request = self._build_request(
239 client=client,
240 url=url,
241 method=method,
242 headers=headers,
243 payload=payload,
244 session=session,
245 timeout=httpx.Timeout(None, connect=timeout.total_seconds()) if timeout else None,
246 )
247
248 try:
249 response = await client.send(http_request, stream=True)
250 except httpx.TimeoutException as exc:
251 raise asyncio.TimeoutError from exc
252
253 try:
254 yield _HttpxResponse(response)
255 finally:
256 await response.aclose()
257
258 def _build_request(
259 self,

Callers

nothing calls this directly

Calls 4

_get_clientMethod · 0.95
_build_requestMethod · 0.95
validate_http_urlFunction · 0.90
_HttpxResponseClass · 0.85

Tested by

no test coverage detected