Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added with statement for requests[Issue #100] #101

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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