cisco-en-programmability/dnacentersdk

Support injection of requests.Session object

Opened this issue · 0 comments

from dnacentersdk import DNACenterAPI
from requests import session
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry


if __name__ == '__main__':

    retries = Retry(
        total=20,
        backoff_factor=0.1,
        status_forcelist=(400, 429, 500, 502, 503, 504),
    )
    http = session()
    http.mount('https://', HTTPAdapter(max_retries=retries))

    api = DNACenterAPI(
        base_url='https://dnac.mydomain.com',
        username=USERNAME,
        password=PASSWORD,
        session=http,
    )

    print(api.devices.get_device_list())
    

We need to be able to inject our own requests.Session object in order to tweak behavior, such as above. Right now, we're monkey-patching the Session object. It would be nice to support injection as a native feature.

I have staged you a pull request for tested code which supports this injection pattern; the snippet above works with the code included in #148