__init__.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """api."""
  2. from __future__ import annotations
  3. from typing import Callable
  4. import wandb
  5. from wandb import env, util
  6. def _disable_ssl() -> Callable[[], None]:
  7. import requests
  8. from urllib3.exceptions import InsecureRequestWarning
  9. # Because third party libraries may also use requests, we monkey patch it globally
  10. # and turn off urllib3 warnings instead printing a global warning to the user.
  11. wandb.termwarn(
  12. "Disabling SSL verification. Connections to this server are not verified and may be insecure!"
  13. )
  14. requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
  15. old_merge_environment_settings = requests.Session.merge_environment_settings
  16. def merge_environment_settings(self, url, proxies, stream, verify, cert):
  17. settings = old_merge_environment_settings(
  18. self, url, proxies, stream, verify, cert
  19. )
  20. settings["verify"] = False
  21. return settings
  22. requests.Session.merge_environment_settings = merge_environment_settings
  23. def reset():
  24. requests.Session.merge_environment_settings = old_merge_environment_settings
  25. return reset
  26. if env.ssl_disabled():
  27. _disable_ssl()
  28. reset_path = util.vendor_setup()
  29. from .internal import Api as InternalApi # noqa
  30. from .public import Api as PublicApi # noqa
  31. reset_path()
  32. __all__ = ["InternalApi", "PublicApi"]