HTTP: Try requests 3 times (with sleep)
Change-Id: I3bb1bbfc3f0454150795c7446ebf6c1b36b410a5
This commit is contained in:
parent
576dec152d
commit
c04e867dc0
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import requests.exceptions
|
||||||
from six.moves import http_client as httplib
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
from surveilclient import exc
|
from surveilclient import exc
|
||||||
@ -21,6 +22,7 @@ from surveilclient.openstack.common.py3kcompat import urlutils
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
USER_AGENT = 'python-surveilclient'
|
USER_AGENT = 'python-surveilclient'
|
||||||
@ -62,7 +64,17 @@ class HTTPClient(object):
|
|||||||
|
|
||||||
auth_url = self.auth_url + '/tokens'
|
auth_url = self.auth_url + '/tokens'
|
||||||
credentials = {}
|
credentials = {}
|
||||||
resp = requests.post(auth_url, data=json.dumps(credentials))
|
|
||||||
|
resp = None
|
||||||
|
for attempt in range(3):
|
||||||
|
try:
|
||||||
|
resp = requests.post(auth_url, data=json.dumps(credentials))
|
||||||
|
break
|
||||||
|
except requests.exceptions.ConnectionError as exp:
|
||||||
|
if attempt == 2:
|
||||||
|
raise exp
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
access = resp.json()
|
access = resp.json()
|
||||||
self.auth_token = access['access']['token']
|
self.auth_token = access['access']['token']
|
||||||
return self.auth_token['id']
|
return self.auth_token['id']
|
||||||
@ -95,7 +107,18 @@ class HTTPClient(object):
|
|||||||
|
|
||||||
request_url = self.endpoint_path + url + '?' + request_params
|
request_url = self.endpoint_path + url + '?' + request_params
|
||||||
|
|
||||||
conn.request(method, request_url, **kwargs)
|
for attempt in range(3):
|
||||||
|
try:
|
||||||
|
conn.request(method, request_url, **kwargs)
|
||||||
|
break
|
||||||
|
except (
|
||||||
|
httplib.BadStatusLine,
|
||||||
|
httplib.IncompleteRead
|
||||||
|
) as exp:
|
||||||
|
if attempt == 2:
|
||||||
|
raise exp
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
|
|
||||||
body_str = resp.read()
|
body_str = resp.read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user