@@ -537,12 +537,12 @@ def _post(self, path, payload):
537
537
:param str path: Formatted Adafruit IO URL from _compose_path
538
538
:param json payload: JSON data to send to Adafruit IO
539
539
"""
540
- response = self ._http .post (
540
+ with self ._http .post (
541
541
path , json = payload , headers = self ._create_headers (self ._aio_headers [0 ])
542
- )
543
- self ._handle_error (response )
544
- json_data = response .json ()
545
- response . close ()
542
+ ) as response :
543
+ self ._handle_error (response )
544
+ json_data = response .json ()
545
+
546
546
return json_data
547
547
548
548
def _get (self , path ):
@@ -551,12 +551,11 @@ def _get(self, path):
551
551
552
552
:param str path: Formatted Adafruit IO URL from _compose_path
553
553
"""
554
- response = self ._http .get (
554
+ with self ._http .get (
555
555
path , headers = self ._create_headers (self ._aio_headers [1 ])
556
- )
557
- self ._handle_error (response )
558
- json_data = response .json ()
559
- response .close ()
556
+ ) as response :
557
+ self ._handle_error (response )
558
+ json_data = response .json ()
560
559
return json_data
561
560
562
561
def _delete (self , path ):
@@ -565,12 +564,12 @@ def _delete(self, path):
565
564
566
565
:param str path: Formatted Adafruit IO URL from _compose_path
567
566
"""
568
- response = self ._http .delete (
567
+ with self ._http .delete (
569
568
path , headers = self ._create_headers (self ._aio_headers [0 ])
570
- )
571
- self ._handle_error (response )
572
- json_data = response .json ()
573
- response . close ()
569
+ ) as response :
570
+ self ._handle_error (response )
571
+ json_data = response .json ()
572
+
574
573
return json_data
575
574
576
575
# Data
0 commit comments