#NEWLINE# def query_api( self , data = None , endpoint = 'SMS' ) : #NEWLINE# #INDENT# url = ( self . api_url % endpoint ) #NEWLINE# if data : #NEWLINE# #INDENT# conn = Request ( url , b ( urlencode ( data ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# conn = Request ( url ) #NEWLINE# #UNINDENT# auth = ( b ( 'Basic ' ) + b64encode ( b ( ( ( self . username + ':' ) + self . password ) ) ) ) #NEWLINE# conn . add_header ( 'Authorization' , auth ) #NEWLINE# try : #NEWLINE# #INDENT# response = urlopen ( conn ) #NEWLINE# #UNINDENT# except HTTPError as err : #NEWLINE# #INDENT# print ( err ) #NEWLINE# print ( "\nSending didn't succeed :(" ) #NEWLINE# exit ( ( - 2 ) ) #NEWLINE# #UNINDENT# return response . read ( )