Skip to content

Commit 3be31ff

Browse files
domhnallwJosie Fegan
andauthored
Attempt to retry requests in the event of transient authentication failures (#133)
* Add HTTP 400 to list of codes to retry on * `black` formatting changes * Copyright year --------- Co-authored-by: Josie Fegan <josie.fegan@hpe.com>
1 parent 9a230cf commit 3be31ff

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

opsramp/base.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Containing various base classes used in other parts of the library
77
# but not intended for direct use by callers.
88
#
9-
# (c) Copyright 2019-2022 Hewlett Packard Enterprise Development LP
9+
# (c) Copyright 2019-2023 Hewlett Packard Enterprise Development LP
1010
#
1111
# Licensed under the Apache License, Version 2.0 (the "License");
1212
# you may not use this file except in compliance with the License.
@@ -69,7 +69,10 @@ def session_add_retry_handler(session=None):
6969
retry = Helpers.create_retry_handler(
7070
retries=7,
7171
backoff_factor=0.5,
72-
status_forcelist=(429,),
72+
status_forcelist=(
73+
400,
74+
429,
75+
),
7376
allowed_methods=http_verbs,
7477
)
7578

@@ -160,7 +163,11 @@ def __init__(self, url, auth, tracker=None, session=None):
160163
self.session = Helpers.session_add_retry_handler()
161164

162165
def __str__(self):
163-
return '%s "%s" "%s"' % (str(type(self)), self.baseurl, self.tracker.fullpath())
166+
return '%s "%s" "%s"' % (
167+
str(type(self)),
168+
self.baseurl,
169+
self.tracker.fullpath(),
170+
)
164171

165172
def clone(self):
166173
new1 = ApiObject(self.baseurl, self.auth, self.tracker.clone(), self.session)
@@ -264,7 +271,12 @@ def prep_headers(self, headers):
264271
def process_result(self, url, resp):
265272
hstatus = int(resp.status_code)
266273
if hstatus < 200 or hstatus >= 300:
267-
msg = "%s %s %s %s" % (resp, resp.request.method, url, resp.content)
274+
msg = "%s %s %s %s" % (
275+
resp,
276+
resp.request.method,
277+
url,
278+
resp.content,
279+
)
268280
LOG.debug(msg)
269281
raise RuntimeError(msg)
270282
try:

0 commit comments

Comments
 (0)