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

Method send_request

src/crawlee/http_clients/_impit.py:156–189  ·  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

154
155 @override
156 async def send_request(
157 self,
158 url: str,
159 *,
160 method: HttpMethod = 'GET',
161 headers: HttpHeaders | dict[str, str] | None = None,
162 payload: HttpPayload | None = None,
163 session: Session | None = None,
164 proxy_info: ProxyInfo | None = None,
165 timeout: timedelta | None = None,
166 ) -> HttpResponse:
167 validate_http_url(url)
168
169 if isinstance(headers, dict) or headers is None:
170 headers = HttpHeaders(headers or {})
171
172 client = self._get_client(proxy_info.url if proxy_info else None, session.cookies.jar if session else None)
173
174 try:
175 response = await client.request(
176 method=method,
177 url=url,
178 content=payload,
179 headers=dict(headers) if headers else None,
180 timeout=timeout.total_seconds() if timeout else None,
181 )
182 except TimeoutException as exc:
183 raise asyncio.TimeoutError from exc
184 except (TransportError, HTTPError) as exc:
185 if self._is_proxy_error(exc):
186 raise ProxyError from exc
187 raise
188
189 return _ImpitResponse(response)
190
191 @asynccontextmanager
192 @override

Callers

nothing calls this directly

Calls 6

_get_clientMethod · 0.95
_is_proxy_errorMethod · 0.95
validate_http_urlFunction · 0.90
HttpHeadersClass · 0.90
_ImpitResponseClass · 0.85
requestMethod · 0.80

Tested by

no test coverage detected