adding a try except in client
This commit is contained in:
parent
dd01c3ef22
commit
7e3c2ffec3
@ -1,4 +1,5 @@
|
||||
import requests
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
|
||||
class Client(object):
|
||||
@ -10,21 +11,31 @@ class Client(object):
|
||||
def usage(self, tenants):
|
||||
url = self.endpoint + "usage"
|
||||
data = {"tenants": tenants}
|
||||
response = requests.post(url,
|
||||
headers={"Content-Type": "application/json",
|
||||
"token": self.auth_token},
|
||||
data=data)
|
||||
if response.status_code != 200:
|
||||
raise AttributeError("Usage cycle failed: " + response.text +
|
||||
" code: " + str(response.status_code))
|
||||
try:
|
||||
response = requests.post(url,
|
||||
headers={"Content-Type":
|
||||
"application/json",
|
||||
"token": self.auth_token},
|
||||
data=data)
|
||||
if response.status_code != 200:
|
||||
raise AttributeError("Usage cycle failed: " + response.text +
|
||||
" code: " + str(response.status_code))
|
||||
|
||||
except ConnectionError:
|
||||
pass
|
||||
|
||||
def sales_order(self, tenants):
|
||||
url = self.endpoint + "sales_order"
|
||||
data = {"tenants": tenants}
|
||||
response = requests.post(url,
|
||||
headers={"Content-Type": "application/json",
|
||||
"token": self.auth_token},
|
||||
data=data)
|
||||
if response.status_code != 200:
|
||||
raise AttributeError("Sales order cycle failed: " + response.text +
|
||||
" code: " + str(response.status_code))
|
||||
try:
|
||||
response = requests.post(url,
|
||||
headers={"Content-Type":
|
||||
"application/json",
|
||||
"token": self.auth_token},
|
||||
data=data)
|
||||
if response.status_code != 200:
|
||||
raise AttributeError("Sales order cycle failed: " +
|
||||
response.text + " code: " +
|
||||
str(response.status_code))
|
||||
except ConnectionError:
|
||||
pass
|
||||
|
@ -9,6 +9,7 @@ if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
#main args:
|
||||
parser.add_argument('--os-username',
|
||||
default=os.environ.get('OS_USERNAME'),
|
||||
help='Defaults to env[OS_USERNAME]')
|
||||
@ -41,6 +42,7 @@ if __name__ == '__main__':
|
||||
help="Config file",
|
||||
default="/etc/artifice/conf.yaml")
|
||||
|
||||
# commands:
|
||||
subparsers = parser.add_subparsers(help='commands', dest='command')
|
||||
|
||||
usage_parser = subparsers.add_parser('usage', help=('process usage' +
|
||||
|
Loading…
x
Reference in New Issue
Block a user