Usecase: I want to find out how many ciphers are supported by the hostname with python request module.
I am not able to find a way to provide the cipher name to request module hook. Can anyone suggest the way to provide the way to specify cipher.
import ssl
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
class Ssl3HttpAdapter(HTTPAdapter):
""""Transport adapter" that allows us to use SSLv3."""
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_SSLv3)
If you are using requests version 2.12.0+, there is a blog post on Configuring TLS With Requests, which describes new functionality to allow you to configure the SSLContext (note that this blog post was written after the OP asked the question):
The following sample code is given as an example of how to re-enable 3DES in Requests using this method.
There is also a hack possible, which you can read on the github pages for the requests module, or at https://stackoverflow.com/a/32651967/2364215 but it modifies the underlying library code, I don't recommend it (neither do the authors of the requests module, as you will find on that page). On the other hand, if you are on an older requests package and you can't upgrade, it may be your best option. It amounts to overriding the urllib3 module's
DEFAULT_CIPHERS
:If you have other code that will use the requests module after doing the modification, but doesn't need the modification, you may want to restore
DEFAULT_CIPHERS
to its previous value.