xively / xively-python

The official pythonic wrapper library for the Xively™ API

Home Page:http://xively.github.io/xively-python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble getting Xively Raspberry Pi Tutorial to work with Python 3.2?

mvartani76 opened this issue · comments

Hi All,

I am new to Xively and relatively new to Raspberry Pi. I followed the tutorial located at https://xively.com/dev/tutorials/pi/ but ran into a few problems.

  1. It appears that the print syntax changed sometime between 2.7 and 3.2 as I had to replace the "s with ( and ) respectively. Not a big problem there.
  2. I receive an "is not JSON serializable" error when running the python script.

Here is the complete error message from the pi...

Starting Xively tutorial script
Found existing datastream
Reading load average
Updating Xively feed with value: b'0.23\n'
Traceback (most recent call last):
  File "xively_tutorial.py", line 64, in <module>
    run()
  File "xively_tutorial.py", line 58, in run
    datastream.update()
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/xively/m                                                   odels.py", line 236, in update
    self._manager.update(self.id, **state)
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/xively/m                                                   anagers.py", line 427, in update
    response = self.client.put(url, data=kwargs)
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/requests                                                   /sessions.py", line 387, in put
    return self.request('PUT', url, data=data, **kwargs)
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/xively/c                                                   lient.py", line 76, in request
    kwargs['data'] = self._encode_data(kwargs['data'])
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/xively/c                                                   lient.py", line 94, in _encode_data
    return encoder.encode(data)
  File "/usr/lib/python3.2/json/encoder.py", line 187, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.2/json/encoder.py", line 245, in iterencode
    return _iterencode(o, 0)
  File "/home/pi/xively_tutorial/.envs/venv/lib/python3.2/site-packages/xively/c                                                   lient.py", line 106, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.2/json/encoder.py", line 169, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'0.23\n' is not JSON serializable

Any help or troubleshooting suggestions would be greatly appreciated.

Python 3.2 is not officially supported, please use either 2.7 or 3.3.