Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 键入对象';SGP30&x27;没有属性';关闭';_Python_Raspberry Pi - Fatal编程技术网

Python 键入对象';SGP30&x27;没有属性';关闭';

Python 键入对象';SGP30&x27;没有属性';关闭';,python,raspberry-pi,Python,Raspberry Pi,我想把我从树莓皮上的传感器中获取的数据发送给Thingspeak。 我真的不知道如何使用python,所以我只“混合”了我在网上找到的一些代码 此代码工作一次,数据发送一次,但“循环”停止并在标题中出现错误。 “with”肯定有问题。我不知道如何关闭该文件 你能帮助我吗? 代码如下: 导入httplib 导入URL库 导入时间 导入系统 进口Adafruit_DHT 从sgp30导入sgp30 从smbus导入smbus key=“xxxxxxx” smbus=smbus(1) def传感器()

我想把我从树莓皮上的传感器中获取的数据发送给Thingspeak。 我真的不知道如何使用python,所以我只“混合”了我在网上找到的一些代码

此代码工作一次,数据发送一次,但“循环”停止并在标题中出现错误。 “with”肯定有问题。我不知道如何关闭该文件 你能帮助我吗? 代码如下:

导入httplib
导入URL库
导入时间
导入系统
进口Adafruit_DHT
从sgp30导入sgp30
从smbus导入smbus
key=“xxxxxxx”
smbus=smbus(1)
def传感器():
以SGP30(smbus)为芯片:
尽管如此:
aq=芯片。测量空气质量()
VOC=aq.VOC\u ppb
二氧化碳=aq.CO2\u ppm
哼,temp=Adafruit\u DHT.读取\u重试(11,4)
params=urllib.urlencode({'field1':temp,'field2':hum,'field3':VOC,'field4':CO2,'key':key})
headers={“Content typZZe”:“application/x-www-form-urlencoded”,“Accept”:“text/plain”}
conn=httplib.HTTPConnection(“api.thingspeak.com:80”)
尝试:
conn.request(“POST”、“/update”、参数、标题)
response=conn.getresponse()
打印(温度、嗡嗡声、挥发性有机化合物、二氧化碳)
打印(response.status、response.reason)
data=response.read()
康涅狄格州关闭
除:
打印(“连接失败”)
打破
芯片。关闭
如果名称=“\uuuuu main\uuuuuuuu”:
尽管如此:
传感器()

小心,除非声明是不好的做法。什么?我不明白