From a2f12fbba18e2b85390d7719ace7c1fe6bce33a1 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Fri, 6 Dec 2024 10:05:14 +0100 Subject: [PATCH] import_documents: rewrite proxies to mounts for httpx 0.28 --- orangecontrib/text/import_documents.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/orangecontrib/text/import_documents.py b/orangecontrib/text/import_documents.py index e18a9e754..bdfc3a44f 100644 --- a/orangecontrib/text/import_documents.py +++ b/orangecontrib/text/import_documents.py @@ -178,6 +178,12 @@ def quote_byte(b): ResponseType = Tuple[Optional[Reader], Optional[TextData], Optional[str]] +def _rewrite_proxies_to_mounts(proxies): + if proxies is None: + return None + return {c: httpx.AsyncHTTPTransport(proxy=url) for c, url in get_proxies().items()} + + class UrlProxyReader: """ A collection of functions to handle async downloading of a list of documents @@ -208,7 +214,8 @@ def read_files( @staticmethod async def _read_files(urls: List[str], callback: Callable) -> List[ResponseType]: - async with httpx.AsyncClient(timeout=10.0, proxies=get_proxies()) as client: + proxy_mounts = _rewrite_proxies_to_mounts(get_proxies()) + async with httpx.AsyncClient(timeout=10.0, mounts=proxy_mounts) as client: req = [UrlProxyReader._read_file(url, client, callback) for url in urls] return await asyncio.gather(*req)