Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def cb(response):
if 200 <= response.status_code < 300:
if response.headers.get('content-type') == 'application/json':
callback(None, response.json())
else:
callback(None, response.text)
else:
callback(AfricasTalkingException(response.text), None)
else:
def cb(response):
if 200 <= response.status_code < 300:
if response.headers.get('content-type') == 'application/json':
callback(None, response.json())
else:
callback(None, response.text)
else:
callback(AfricasTalkingException(response.text), None)
if method == 'GET':
_target = self.__make_get_request
elif method == 'POST':
_target = self.__make_post_request
else:
raise AfricasTalkingException('Unexpected HTTP method: ' + method)
thread = threading.Thread(target=_target, args=(url, headers, data, params, cb))
thread.start()
return thread
if callback is None:
if method == 'GET':
res = self.__make_get_request(url=url, headers=headers, data=data, params=params)
elif method == 'POST':
res = self.__make_post_request(url=url, headers=headers, data=data, params=params)
else:
raise AfricasTalkingException('Unexpected HTTP method: ' + method)
if 200 <= res.status_code < 300:
if res.headers.get('content-type') == 'application/json':
return res.json()
else:
return res.text
else:
raise AfricasTalkingException(res.text)
elif not callable(callback):
raise RuntimeError('callback has to be callable. e.g. a function')
else:
def cb(response):
if 200 <= response.status_code < 300:
if response.headers.get('content-type') == 'application/json':
callback(None, response.json())
else:
callback(None, response.text)
else:
callback(AfricasTalkingException(response.text), None)
if method == 'GET':
_target = self.__make_get_request
elif method == 'POST':
_target = self.__make_post_request