Jump to content


Problem to POST the 11° data

  • Please log in to reply
2 replies to this topic

#1 bimaca



  • Members
  • Pip
  • 2 posts

Posted 07 February 2018 - 11:18 AM

Dear frends,
I am working on a project with carriots. On my PC i run a program in python3 that post on carriots some data. All work fine for the ten first data, but when i try to post the data 11° i receive:
Traceback (most recent call last):
  File "xxx.py", line 41, in <module>
    f = urllib.request.urlopen(req)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized

The code on python is:
import http.client
import urllib.request
import urllib.parse
import json
import time

api_url = "https://api.carriots.com/streams"
device = "defaultDevice@xx.xx"
api_key = "----API-KEY------"

temperature = 0.0
humidity = 0.0
while True:
    print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
    timestamp = int(time.time())
    params = {"protocol":"v2", "device": device, "at":timestamp, "data":dict(temp=temperature, hum=humidity)}
    binary_data = json.dumps(params).encode('ascii')
    header = {"User-Agent":"defaultDevice", "Content-Type":"application/json", "carriots.apikey":api_key}
    req = urllib.request.Request(api_url,binary_data,header)
    f = urllib.request.urlopen(req)

Thanks for your helps!

#2 sdeancos


    Master of Puppets

  • Members
  • PipPipPip
  • 108 posts
  • LocationMadrid, Spain.

Posted 08 February 2018 - 10:59 AM

Hi bimaca,

The free account have a limit of 10 streams for minute and 500 streams for day.

You can see more info about limits in https://www.carriots.com/pricing


#3 bimaca



  • Members
  • Pip
  • 2 posts

Posted 08 February 2018 - 02:11 PM

Thanks for your repply!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users