Skip to content

Commit 80b455a

Browse files
authored
TypeError Handling (#61)
Fix TypeError on 3.5.x (RasPi, Stretch)
1 parent 9ef016e commit 80b455a

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

Diff for: Adafruit_IO/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.0"
1+
__version__ = "2.0.11"

Diff for: Adafruit_IO/client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ def _compose_url(self, path, is_time=None):
6868

6969

7070
def _handle_error(self, response):
71-
# Handle explicit errors.
71+
# Throttling Error
7272
if response.status_code == 429:
7373
raise ThrottlingError()
74+
# Resource on AdafruitIO not Found Error
75+
elif response.status_code == 400:
76+
raise RequestError(response)
7477
# Handle all other errors (400 & 500 level HTTP responses)
7578
elif response.status_code >= 400:
7679
raise RequestError(response)

Diff for: Adafruit_IO/errors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
import json
22+
import json, requests
2323

2424
# MQTT RC Error Types
2525
MQTT_ERRORS = [ 'Connection successful',
@@ -42,9 +42,9 @@ def __init__(self, response):
4242
response.status_code, response.reason, error_message))
4343

4444
def _parse_error(self, response):
45+
content = response.json()
4546
try:
46-
content = json.loads(response.content)
47-
return ' - '.join(content['error'])
47+
return content['error']
4848
except ValueError:
4949
return ""
5050

Diff for: examples/api/simple.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Author: Tony DiCola
44

55
# Import Adafruit IO REST client.
6-
from Adafruit_IO import Client
6+
from Adafruit_IO import Client, RequestError, Feed
77

88
# Set to your Adafruit IO key.
99
# Remember, your key is a secret,
@@ -17,20 +17,34 @@
1717
# Create an instance of the REST client.
1818
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
1919

20+
# Assign a foo feed, if one exists already
21+
try:
22+
foo = aio.feeds('foo')
23+
except RequestError: # Doesn't exist, create a new feed
24+
feed = Feed(name="foo")
25+
foo = aio.create_feed(feed)
26+
27+
# Assign a test feed, if one exists already
28+
try:
29+
test = aio.feeds('test')
30+
except RequestError: # Doesn't exist, create a new feed
31+
feed = Feed(name="test")
32+
test = aio.create_feed(feed)
33+
2034
# Send a value to the feed 'Test'.
21-
aio.send_data('Test', 42)
35+
aio.send_data(test.key, 42)
2236

2337
# Send a string value 'bar' to the feed 'Foo'.
24-
aio.send_data('Foo', 'bar')
38+
aio.send_data(foo.key, 'bar')
2539

2640
# Now read the most recent value from the feed 'Test'. Notice that it comes
2741
# back as a string and should be converted to an int if performing calculations
2842
# on it.
29-
data = aio.receive('Test')
43+
data = aio.receive(test.key)
3044
print('Retrieved value from Test has attributes: {0}'.format(data))
3145
print('Latest value from Test: {0}'.format(data.value))
3246

3347
# Finally read the most revent value from feed 'Foo'.
34-
data = aio.receive('Foo')
48+
data = aio.receive(foo.key)
3549
print('Retrieved value from Foo has attributes: {0}'.format(data))
3650
print('Latest value from Foo: {0}'.format(data.value))

Diff for: setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
'License :: OSI Approved :: MIT License',
3737
'Intended Audience :: Developers',
3838
'Programming Language :: Python :: 3',
39+
'Programming Language :: Python :: 3.4',
40+
'Programming Language :: Python :: 3.5',
3941
'Programming Language :: Python :: 3.6',
4042
'Topic :: Home Automation',
4143
'Topic :: Software Development']
@@ -59,8 +61,6 @@
5961

6062
version = verstr,
6163
install_requires = ["requests", "paho-mqtt"],
62-
python_requires = ">=3.6.0",
63-
6464

6565

6666
packages = ['Adafruit_IO'],

0 commit comments

Comments
 (0)