refactor requests
This commit is contained in:
parent
e119514852
commit
5526cc8b16
@ -52,33 +52,24 @@ class API(object):
|
||||
url = self.base + uri
|
||||
auth = requests.auth.HTTPBasicAuth(self.username, self.password)
|
||||
|
||||
kwargs = dict(auth=auth, verify=True, timeout=3.0)
|
||||
if params:
|
||||
kwargs.update(params=params)
|
||||
|
||||
if method == "GET":
|
||||
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)
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user