013ReviewmidPython / Requests真实来源改编 Requests

Requests:包装 urllib3 连接池异常

审查一个 Requests adapter PR:作者捕获 urllib3 的 ClosedPoolError,并把它转换成 Requests 的 ConnectionError。

ai-pr.diffdiff · 14 lines
diff --git a/requests/adapters.py b/requests/adapters.py@@+from .packages.urllib3.exceptions import ClosedPoolError@@+        except ClosedPoolError as e:+            raise ConnectionError(e, request=request)+         except _ProxyError as e:             raise ProxyError(e)@@+def test_closed_pool_error_is_wrapped():+    with pytest.raises(ConnectionError):+        raise_wrapped_closed_pool_error()