#NEWLINE# def json_request( self , method , url , **kwargs ) : #NEWLINE# #INDENT# kwargs . setdefault ( 'headers' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# kwargs [ 'headers' ] . setdefault ( 'Content-Type' , 'application/json' ) #NEWLINE# kwargs [ 'headers' ] . setdefault ( 'Accept' , 'application/json' ) #NEWLINE# if ( 'body' in kwargs ) : #NEWLINE# #INDENT# kwargs [ 'body' ] = json . dumps ( kwargs [ 'body' ] ) #NEWLINE# #UNINDENT# ( resp , body_iter ) = self . _http_request ( url , method , ** kwargs ) #NEWLINE# content_type = resp . getheader ( 'content-type' , None ) #NEWLINE# if ( ( resp . status == 204 ) or ( resp . status == 205 ) or ( content_type is None ) ) : #NEWLINE# #INDENT# return ( resp , list ( ) ) #NEWLINE# #UNINDENT# if ( 'application/json' in content_type ) : #NEWLINE# #INDENT# body = '' . join ( [ chunk for chunk in body_iter ] ) #NEWLINE# try : #NEWLINE# #INDENT# body = json . loads ( body ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# LOG . error ( 'Could not decode response body as JSON' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# body = None #NEWLINE# #UNINDENT# return ( resp , body )