Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.


by groznigaspr on Tue Mar 17, 2020 1:06 pm

i am having trouble with uploading image into the feed. i capture image on raspberry camera and lower it's quality and then encode it. i try to send it withaio.send and get following error. i found out that picture is encoded correctly(becasue i dragged the same picture into the feed and cheched its value it's the same as encoded picture. I tried to decode that image and it was displayed correctly)

i am getting error

Traceback (most recent call last):
File "", line 31, in <module>
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/", line 154, in send_data
return self.create_data(feed, payload)
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/", line 254, in create_data
return Data.from_dict(self._post(path, data._asdict()))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/", line 126, in _post
File "/usr/lib/python3.5/json/", line 230, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.5/json/", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.5/json/", line 256, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.5/json/", line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'/9j/4AAQSkZJRgABAQAAAQABAAD........ a lot of text.........j/2Q==' is not JSON serializable


import io
from Adafruit_IO import*
from PIL import Image
import base64
import picamera

aio = Client("xxxxxxxxxxx", "xxxxxxxxxxxxxxx")


stream = io.BytesIO()
camera.capture(stream, format='jpeg', resize=(800, 600))

print('> optimizing')
image =, 'r')

optim_stream = io.BytesIO(), format='jpeg', quality=70, optimize=True)

print('> converting')
value = base64.b64encode(

if len(value) > 102400:
print ("image is too big!")


Posts: 1
Joined: Tue Mar 17, 2020 12:49 pm

Re: aio.send(image)

by brubell on Thu Mar 19, 2020 10:19 am

JSON can't handle raw bytes, that why you're getting this error. Could you try converting the base64 bytes object into a string for the call to aio.send:

Code: Select all | TOGGLE FULL SIZE
b64_string = value.decode('utf-8')

Posts: 792
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.