Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support injection of requests.Session object #149

Closed
andrewschenck opened this issue Mar 5, 2024 · 1 comment
Closed

Support injection of requests.Session object #149

andrewschenck opened this issue Mar 5, 2024 · 1 comment

Comments

@andrewschenck
Copy link

andrewschenck commented Mar 5, 2024

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

@bvargasre
Copy link
Collaborator

I'm going to close this issue, in the new version this is the change of the PR.
Any problems that arise feel free to open a new issue or reopen this one.
Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants