[SOLVED] Maximum number of values able to be sent with a single variable using Python SDK

Hello everyone, just thought I’d share something I’ve recently seen with the Python API and that I couldn’t find posted anywhere online.

I have been trying to post a list of values with an associated timestamp to Ubidots every 10 seconds using:
variable.send_values([{"value":val1, "timestamp":time1}, {"value":val2, "timestamp":time2}, etc...])

I found that the maximum number of values you can send is 200. My testing:
List sizes: 111, 193, 200 - Able to be sent.
List sizes: 202, 215, 219, 233, 317, 520 - ubidots.apiclient.UbidotsForbiddenError: Your token is invalid or you don't have permissions to access this resource
List size: 924 - requests.exceptions.ConnectionError: ('Connection aborted.', error(32, 'Broken pipe'))

If you know of a better way to send the data, I would be very appreciative if you could please let me know.

Thanks!

Hello @jeremy,

To handle the data with Python and Ubidots we highly recommend use requests. In the following guide you will find an example of the code. Take in count that he maximum size for the payload is the 10K bytes.

All the best,
Maria C.

Thanks for the guide!

I gave it a go, but couldn’t get the POST request to work:

def payloader(measurements, timestamps):
    payload = []
    for x in xrange(len(measurements)-1):
        payload.append({str("value"): measurements[x], str("timestamp"): timestamps[x]})

    payload = json.dumps(payload, ensure_ascii=True)
    return payload

However, when I attempt to use this function, I get the following error:

{u'non_field_errors': [u'Invalid data. Expected a dictionary, but got unicode.']}

My payload output looks like this (which according to the Ubidots website is correct):

[{"timestamp": 1518589188000, "value": "2.772"}, {"timestamp": 1518589189000, "value": "2.763"}]

I’m pretty new to generating JSON files so I’m not really sure how to go about it.

Has anyone else run into this problem before?

Hello @jeremy,

As I can notes you are missing the variable assignment. Please reference to the request below to get a better idea how to build the payload properly:

curl -X POST -H "Content-Type: application/json" -d '{"my-variable":[{"timestamp": 1518589188000, "value": "2.772"}, {"timestamp": 1518589189000, "value": "2.763"}]}' "http://things.ubidots.com/api/v1.6/devices/test-support?token={assign_your_ubidots_token_here}" 

Server Response:

{"my-variable": [{"status_code": 201}, {"status_code": 201}]}

Ubidots side:

Selection_083

I hope this would help you.

All the best,
Maria C.