From 2e620c71fd5750ca6784c5c37dcb3fd094ef0286 Mon Sep 17 00:00:00 2001 From: wayyoungboy <1017761807@qq.com> Date: Sun, 7 Jun 2026 06:34:46 +0800 Subject: [PATCH] Document pickling custom transport adapters --- docs/user/advanced.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index f5209a5a53..d5ff4ed840 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -1024,10 +1024,22 @@ library to use SSLv3:: class Ssl3HttpAdapter(HTTPAdapter): """"Transport adapter" that allows us to use SSLv3.""" + __attrs__ = HTTPAdapter.__attrs__ + ["ssl_version"] + + def __init__(self, ssl_version=ssl.PROTOCOL_SSLv3, **kwargs): + self.ssl_version = ssl_version + super().__init__(**kwargs) + def init_poolmanager(self, connections, maxsize, block=False): self.poolmanager = PoolManager( num_pools=connections, maxsize=maxsize, - block=block, ssl_version=ssl.PROTOCOL_SSLv3) + block=block, ssl_version=self.ssl_version) + +If a custom Transport Adapter stores extra instance attributes, extend +``HTTPAdapter.__attrs__`` with those attribute names. Requests uses this list +when pickling adapters, which can happen when a :class:`Session +` is copied or serialized. Without listing custom state in +``__attrs__``, unpickling the adapter may lose that state. Example: Automatic Retries ^^^^^^^^^^^^^^^^^^^^^^^^^^