使用Python2.7 GET Onenet平台的数据
效果
代码
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: requests1
Description :
Author : 神秘藏宝室
date: 2018-02-01
-------------------------------------------------
Change Activity:
2018-02-01:
-------------------------------------------------
"""
import requests
import json
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
#设备ID
DEVICEID = '3225187'
#数据流名称
SENSORID = 'TEST'
#APIKEY
APIKEY = 'R9xO5NZm6oVI4YBHvCPKEqtwYtMA'
url = 'http://api.heclouds.com/devices/%s/datastreams/%s'%(DEVICEID,SENSORID)
print url
headers = {
"api-key":APIKEY,
"Connection":"close"
}
r = requests.get(url,headers=headers)
print r.headers
print '1',20 * '*'
print r.content
print '2',20 * '*'
print r.text
print '3',20 * '*'
print ('从Onenet获取的ID为%s获取的最新数据是:%d'
% (json.loads(r.content)['data']['id'],
json.loads(r.content)['data']['current_value']))
文章对您有帮助,开心可以打赏我,金额随意,欢迎来赏!
需要电子方面开发板/传感器/模块等硬件可以到我的淘宝店逛逛