|
|
|
@ -52,33 +52,24 @@ class API(object):
|
|
|
|
|
url = self.base + uri
|
|
|
|
|
auth = requests.auth.HTTPBasicAuth(self.username, self.password)
|
|
|
|
|
|
|
|
|
|
if method == "GET":
|
|
|
|
|
kwargs = dict(auth=auth, verify=True, timeout=3.0)
|
|
|
|
|
if params:
|
|
|
|
|
r = requests.get(url, auth=auth, params=params, verify=True, timeout=3.0)
|
|
|
|
|
else:
|
|
|
|
|
r = requests.get(url, auth=auth, verify=True, timeout=3.0)
|
|
|
|
|
kwargs.update(params=params)
|
|
|
|
|
|
|
|
|
|
if method == "GET":
|
|
|
|
|
fn = requests.get
|
|
|
|
|
|
|
|
|
|
elif method == "POST":
|
|
|
|
|
fn = requests.post
|
|
|
|
|
headers = {"content-type": "application/json"}
|
|
|
|
|
if params:
|
|
|
|
|
r = requests.post(
|
|
|
|
|
url,
|
|
|
|
|
auth=auth,
|
|
|
|
|
headers=headers,
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
params=params,
|
|
|
|
|
verify=True,
|
|
|
|
|
timeout=3.000,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
r = requests.post(
|
|
|
|
|
url,
|
|
|
|
|
auth=auth,
|
|
|
|
|
headers=headers,
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
verify=True,
|
|
|
|
|
timeout=3.000,
|
|
|
|
|
)
|
|
|
|
|
kwargs.update(headers=headers,data=json.dumps(data))
|
|
|
|
|
|
|
|
|
|
elif method == "PUT":
|
|
|
|
|
fn = requests.post
|
|
|
|
|
headers = {"content-type": "application/json"}
|
|
|
|
|
kwargs.update(headers=headers,data=json.dumps(data))
|
|
|
|
|
|
|
|
|
|
r = fn(url, **kwargs)
|
|
|
|
|
|
|
|
|
|
if (r.status_code == 200) or (r.status_code == 201):
|
|
|
|
|
try:
|
|
|
|
|