Skip to content
Myr

Added an SSL TA example.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dustin Oprea · committed by Dustin Oprea · parent 0f40d81 · Browse files · 1 file+34 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+34 added−2 removed

  • other:+34 added−2 removed

1 file+34 added−2 removed

modified:docs/user/advanced.rst+34 added-2 removed
602 unmodified lines
603The mount call registers a specific instance of a Transport Adapter to a604prefix. Once mounted, any HTTP request made using that session whose URL starts605with the given prefix will use the given Transport Adapter.606607Implementing a Transport Adapter is beyond the scope of this documentation, but608a good start would be to subclass the ``requests.adapters.BaseAdapter`` class.607Many of the details of implementing a Transport Adapter are beyond the scope of608this documentation, but take a look at the next example for a simple SSL use-609case. For more than that, you might look at subclassing 610``requests.adapters.BaseAdapter``.611612Example: Specific SSL Version613-----------------------------614615The Requests team has made a specific choice to use whatever SSL version is 616default in the underlying library (`urllib3`_). Normally this is fine, but from 617time to time, you might find yourself needing to connect to a service-endpoint 618that uses a version that isn't compatible with the default.619620You can use Transport Adapters for this by taking most of the existing 621implementation of HTTPAdapter, and adding a parameter *ssl_version* that gets 622passed-through to `urllib3`. We'll make a TA that instructs the library to use 623SSLv3:624625::626627 import ssl628629 from requests.adapters import HTTPAdapter630 from requests.packages.urllib3.poolmanager import PoolManager631632633 class Ssl3HttpAdapter(HTTPAdapter):634 """"Transport adapter" that allows us to use SSLv3."""635636 def init_poolmanager(self, connections, maxsize, block=False):637 self.poolmanager = PoolManager(num_pools=connections,638 maxsize=maxsize,639 block=block,640 ssl_version=ssl.PROTOCOL_SSLv3)641642.. _`described here`: http://kennethreitz.org/exposures/the-future-of-python-http643.. _`urllib3`: https://github.com/shazow/urllib3644645Blocking Or Non-Blocking?
15 unmodified lines