@@ -88,7 +88,7 @@ def prepare_response(self, request):
8888 jsondata = request .text
8989 try :
9090 jsondata = json .loads (jsondata )
91- except :
91+ except ( ValueError , TypeError ) :
9292 pass
9393
9494 return {
@@ -111,17 +111,10 @@ def prepare_response(self, request):
111111 def summarize_responses (self , one_response , summary ):
112112 summary ["results" ].append (one_response )
113113
114- # if ONE request fails, summary is marked as failed
115114 if not one_response ["success" ]:
116115 summary ["success" ] = False
117116
118- # surface a non-2xx status code on the summary
119- try :
120- code = int (one_response ["status" ])
121- except (ValueError , TypeError ):
122- code = 0
123- if not (200 <= code < 300 ):
124- summary ["status" ] = one_response ["status" ]
117+ summary ["status" ] = one_response ["status" ]
125118
126119 return summary
127120
@@ -132,14 +125,9 @@ def Send_SMS(self, url, headers="", username="", password="", body="", From="",
132125 parsed_headers = self .splitheaders (headers )
133126 parsed_headers ["User-Agent" ] = "Shuffle Automation"
134127
135- auth = None
136- if username or password :
137- # Shouldn't be used if authorization headers exist
138- if "Authorization" in parsed_headers :
139- #print("Found authorization - skipping username & pw")
140- pass
141- else :
142- auth = requests .auth .HTTPBasicAuth (username , password )
128+ auth = None
129+ if (username or password ) and "Authorization" not in parsed_headers :
130+ auth = requests .auth .HTTPBasicAuth (username , password )
143131
144132 if not timeout :
145133 timeout = 5
@@ -153,7 +141,7 @@ def Send_SMS(self, url, headers="", username="", password="", body="", From="",
153141
154142 summary = {
155143 "success" : True ,
156- "status" : "200" ,
144+ "status" : None ,
157145 "url" : url ,
158146 "results" : []
159147 }
@@ -166,8 +154,11 @@ def Send_SMS(self, url, headers="", username="", password="", body="", From="",
166154
167155 payload = {"src" : From , "dst" : dst , "text" : body , "type" : "sms" }
168156
169- request = requests .post (url , headers = parsed_headers , auth = auth , json = payload , timeout = timeout )
170- response = self .prepare_response (request )
157+ try :
158+ request = requests .post (url , headers = parsed_headers , auth = auth , json = payload , timeout = timeout )
159+ response = self .prepare_response (request )
160+ except Exception as e :
161+ response = {"success" : False , "status" : "XXX" , "error" : str (e )}
171162 summary = self .summarize_responses (response , summary )
172163
173164 return json .dumps (summary )
@@ -179,8 +170,6 @@ def run(request):
179170 action = request .get_json ()
180171 print (action )
181172 print (type (action ))
182- authorization_key = action .get ("authorization" )
183- current_execution_id = action .get ("execution_id" )
184173
185174 if action and "name" in action and "app_name" in action :
186175 PLIVO .run (action )
0 commit comments