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 older versions of urllib3 and Databricks Runtime with regards to DEFAULT_METHOD_WHITELIST change to DEFAULT_ALLOWED_METHODS #240

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion databricks/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,20 @@ def __init__(self, cfg: Config = None):
self._debug_truncate_bytes = cfg.debug_truncate_bytes if cfg.debug_truncate_bytes else 96
self._user_agent_base = cfg.user_agent

# Since urllib3 v1.26.0, Retry.DEFAULT_METHOD_WHITELIST is deprecated in favor of
# Retry.DEFAULT_ALLOWED_METHODS. We need to support both versions.
if 'DEFAULT_ALLOWED_METHODS' in dir(Retry):
retry_kwargs = {'allowed_methods': {"POST"} | set(Retry.DEFAULT_ALLOWED_METHODS)}
else:
retry_kwargs = {'method_whitelist': {"POST"} | set(Retry.DEFAULT_METHOD_WHITELIST)}

retry_strategy = Retry(
total=6,
backoff_factor=1,
status_forcelist=[429],
allowed_methods={"POST"} | set(Retry.DEFAULT_ALLOWED_METHODS),
respect_retry_after_header=True,
raise_on_status=False, # return original response when retries have been exhausted
**retry_kwargs,
)

self._session = requests.Session()
Expand Down