Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_response(operation, addr, data=None, headers={}, silent=False, die_on_error=True, domain=Domain.API):
"""
Returns response from the domain or API server.
"""
response = None
conn = None
try:
conn = domain_connect(config, domain, Domain)
do_request(conn, operation, addr, data, headers)
response = conn.getresponse()
return response, conn
except socket.sslerror, msg: # Network error
if not silent:
log.info("SSL error: %s", msg)
except socket.error, msg: # Network error
if not silent:
log.debug("Network error: %s", msg)
except httplib.BadStatusLine:
error = "Internal error, bad status line"
if die_on_error:
die(error)
else:
log.info(error)