@@ -100,10 +100,7 @@ def get_hub_message(self):
100
100
path = "{0}/devices/{1}/messages/deviceBound?api-version={2}" .format (self ._iot_hub_url ,
101
101
self ._device_id ,
102
102
AZ_API_VER )
103
- try :
104
- data = self ._get (path , is_c2d = True )
105
- except RuntimeError :
106
- raise RuntimeError ('HTTP C2D messages are HEAVILY throttled - poll every 25 mins.' )
103
+ data = self ._get (path , is_c2d = True )
107
104
if data == 204 : # device's message queue is empty
108
105
return - 1
109
106
etag = data [1 ]['etag' ]
@@ -190,12 +187,18 @@ def _get(self, path, is_c2d=False):
190
187
response = self ._wifi .get (
191
188
path ,
192
189
headers = self ._azure_header )
193
- if is_c2d : # check status of azure message queue
194
- if response .status_code == 200 :
195
- return response .text , response .headers
196
- return response .status_code
197
- self ._parse_http_status (response .status_code , response .reason )
198
- return response .json ()
190
+ status_code = response .status_code
191
+ if is_c2d :
192
+ if status_code == 200 :
193
+ data = response .text
194
+ headers = response .headers
195
+ response .close ()
196
+ return data , headers
197
+ response .close ()
198
+ return status_code
199
+ json = response .json ()
200
+ response .close ()
201
+ return json
199
202
200
203
def _delete (self , path , etag = None ):
201
204
"""HTTP DELETE
@@ -209,7 +212,9 @@ def _delete(self, path, etag=None):
209
212
path ,
210
213
headers = data_headers )
211
214
self ._parse_http_status (response .status_code , response .reason )
212
- return response .status_code
215
+ status_code = response .status_code
216
+ response .close ()
217
+ return status_code
213
218
214
219
def _patch (self , path , payload ):
215
220
"""HTTP PATCH
@@ -221,7 +226,9 @@ def _patch(self, path, payload):
221
226
json = payload ,
222
227
headers = self ._azure_header )
223
228
self ._parse_http_status (response .status_code , response .reason )
224
- return response .json ()
229
+ json_data = response .json ()
230
+ response .close ()
231
+ return json_data
225
232
226
233
def _put (self , path , payload = None ):
227
234
"""HTTP PUT
@@ -233,4 +240,6 @@ def _put(self, path, payload=None):
233
240
json = payload ,
234
241
headers = self ._azure_header )
235
242
self ._parse_http_status (response .status_code , response .reason )
236
- return response .json ()
243
+ json_data = response .json ()
244
+ response .close ()
245
+ return json_data
0 commit comments