Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR Feedback
* Fixed typo
* Removed Retry on `DEFAULT_REFRESH_STATUS_CODES` in the OAUTH2.0 code
* Add TOO_MANY_REQUESTS status code
  • Loading branch information
clundin25 committed Sep 7, 2022
commit f04a1bbe0f9604a465be229eca7dc36b7077bf03
3 changes: 3 additions & 0 deletions google/auth/transport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
import six
from six.moves import http_client

TOO_MANY_REQUESTS = 429 # Python 2.7 six is missing this status code.

DEFAULT_RETRYABLE_STATUS_CODES = (
http_client.INTERNAL_SERVER_ERROR,
http_client.SERVICE_UNAVAILABLE,
http_client.REQUEST_TIMEOUT,
TOO_MANY_REQUESTS,
)
"""Sequence[int]: HTTP status codes indicating a request can be retried.
"""
Expand Down
13 changes: 7 additions & 6 deletions google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _handle_error_response(response_data, retryable_error):

Args:
response_data (Mapping | str): The decoded response data.
retryable_error Optional[bool]: A boolean indicating if an error is retry able.
retryable_error Optional[bool]: A boolean indicating if an error is retryable.
Defaults to False.

Raises:
Expand Down Expand Up @@ -89,18 +89,19 @@ def _can_retry(status_code, response_data):

# Per Oauth 2.0 RFC https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.2.1
# This is needed because a redirect will not return a 500 status code.
retryable_error_descriptions = {"internal_failure", "server_error", "temporarily_unavailable"}
retryable_error_descriptions = {
"internal_failure",
"server_error",
"temporarily_unavailable",
}

if any(e in retryable_error_descriptions for e in (error_code, error_desc)):
return True

except AttributeError:
pass

return (
status_code in transport.DEFAULT_REFRESH_STATUS_CODES
or status_code in transport.DEFAULT_RETRYABLE_STATUS_CODES
)
return status_code in transport.DEFAULT_RETRYABLE_STATUS_CODES


def _parse_expiry(response_data):
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
5 changes: 1 addition & 4 deletions tests/oauth2/test__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def test__handle_error_response_not_json():


def test__can_retry_retryable():
retryable_codes = (
transport.DEFAULT_RETRYABLE_STATUS_CODES
+ transport.DEFAULT_REFRESH_STATUS_CODES
)
retryable_codes = transport.DEFAULT_RETRYABLE_STATUS_CODES
for status_code in range(100, 600):
if status_code in retryable_codes:
assert _client._can_retry(status_code, {"error": "invalid_scope"})
Expand Down