#NEWLINE# def _make_request( self , method , url , body = None , headers = None ) : #NEWLINE# #INDENT# 'Make a single HTTP request to the API and return the\n        HTTPResponse object.' #NEWLINE# log = self . logger #NEWLINE# url = ( self . path + url ) #NEWLINE# if ( headers is None ) : #NEWLINE# #INDENT# headers = [ ] #NEWLINE# #UNINDENT# headers . append ( ( 'User-Agent' , 'TestMill/1.0' ) ) #NEWLINE# headers . append ( ( 'Accept' , 'application/json, */*' ) ) #NEWLINE# if ( self . _cookie is not None ) : #NEWLINE# #INDENT# headers . append ( ( 'Cookie' , self . _cookie ) ) #NEWLINE# #UNINDENT# if ( body is None ) : #NEWLINE# #INDENT# body = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# body = json . dumps ( body ) #NEWLINE# headers . append ( ( 'Content-Type' , 'application/json' ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# log . debug ( 'API request: %s %s, %d bytes' , method , url , len ( body ) ) #NEWLINE# response = self . _retry_request ( method , url , body , dict ( headers ) ) #NEWLINE# #UNINDENT# except ( socket . error , ssl . SSLError , httplib . HTTPException ) as e : #NEWLINE# #INDENT# log . error ( 'error making API call: %s' , str ( e ) ) #NEWLINE# raise RavelloError ( str ( e ) ) #NEWLINE# #UNINDENT# body = response . body #NEWLINE# ctype = response . getheader ( 'Content-Type' ) #NEWLINE# log . debug ( 'API response: {0}, {1} bytes, ({2})' . format ( response . status , len ( body ) , ctype ) ) #NEWLINE# if ( 200 <= response . status < 300 ) : #NEWLINE# #INDENT# if ( ctype == 'application/json' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# parsed = json . loads ( body ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# log . error ( 'response body contains invalid JSON' ) #NEWLINE# return #NEWLINE# #UNINDENT# response . entity = parsed #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response . entity = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( response . status == 404 ) or ( ( ( response . status == 500 ) and ( 'not found' in response . getheader ( 'error-message' , '' ) ) ) or ( 'not exist' in response . getheader ( 'error-message' , '' ) ) or ( 'was deleted' in response . getheader ( 'error-message' , '' ) ) ) ) : #NEWLINE# #INDENT# response . entity = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error = response . getheader ( 'error-code' ) #NEWLINE# message = response . getheader ( 'error-message' , '' ) #NEWLINE# if error : #NEWLINE# #INDENT# log . debug ( 'API detail: {0}: {1}' . format ( error , message ) ) #NEWLINE# #UNINDENT# if ( not e ) : #NEWLINE# #INDENT# message = 'API call failed with {0} {1}' . format ( response . status , response . reason ) #NEWLINE# #UNINDENT# raise RavelloError ( message ) #NEWLINE# #UNINDENT# #UNINDENT# return response