Skip to content

Commit

Permalink
Merge pull request #101 from muddi900/add/context-manager
Browse files Browse the repository at this point in the history
Added with statement for requests[Issue #100]
  • Loading branch information
dhalbert authored May 11, 2023
2 parents cdaf615 + 156147d commit 91efc34
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions adafruit_io/adafruit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,12 @@ def _post(self, path, payload):
:param str path: Formatted Adafruit IO URL from _compose_path
:param json payload: JSON data to send to Adafruit IO
"""
response = self._http.post(
with self._http.post(
path, json=payload, headers=self._create_headers(self._aio_headers[0])
)
self._handle_error(response)
json_data = response.json()
response.close()
) as response:
self._handle_error(response)
json_data = response.json()

return json_data

def _get(self, path):
Expand All @@ -551,12 +551,11 @@ def _get(self, path):
:param str path: Formatted Adafruit IO URL from _compose_path
"""
response = self._http.get(
with self._http.get(
path, headers=self._create_headers(self._aio_headers[1])
)
self._handle_error(response)
json_data = response.json()
response.close()
) as response:
self._handle_error(response)
json_data = response.json()
return json_data

def _delete(self, path):
Expand All @@ -565,12 +564,12 @@ def _delete(self, path):
:param str path: Formatted Adafruit IO URL from _compose_path
"""
response = self._http.delete(
with self._http.delete(
path, headers=self._create_headers(self._aio_headers[0])
)
self._handle_error(response)
json_data = response.json()
response.close()
) as response:
self._handle_error(response)
json_data = response.json()

return json_data

# Data
Expand Down

0 comments on commit 91efc34

Please sign in to comment.