while connect to firebase get NameError: name 'request' is not defined
while connect to firebase get NameError: name 'request' is not defined
我有一个期末项目,所以我需要一些帮助来显示带有 firebase 的温度传感器,我正在使用 Raspberry Pi B+ 和一个 DS18B20 传感器,我写了 firebase 的所有命令,它只保留最后一个这一步是当我从计算机连接到 firebase 时我必须找到温度。
任何人都可以帮助我吗?谢谢
Copy from comment: I cant copy all the code here because its too long :
import os, glob, time, calendar, json
from urllib.request import urlopen
while True:
url = 'projetfindetude-4dae9.firebaseio.com/database.json'
postdata = { 'datetime': str(calendar.timegm(time.gmtime())), 'sensorId': "1", 'tempRecord': str(read_temp()) }
req = Request(url)
req.add_header('Content-Type','application/json')
data = json.dumps(postdata)
response = urlopen(req,data)
the error:
req = request(url) NameError: name 'request' is not defined
语句 from urllib.request import urlopen
仅导入 urlopen
。如果要调用 Request
,则需要专门导入 Request
,或者导入整个 urllib.request
模块(然后将 Request
调用为 urllib.request.Request
) .
我有一个期末项目,所以我需要一些帮助来显示带有 firebase 的温度传感器,我正在使用 Raspberry Pi B+ 和一个 DS18B20 传感器,我写了 firebase 的所有命令,它只保留最后一个这一步是当我从计算机连接到 firebase 时我必须找到温度。 任何人都可以帮助我吗?谢谢
Copy from comment: I cant copy all the code here because its too long :
import os, glob, time, calendar, json
from urllib.request import urlopen
while True:
url = 'projetfindetude-4dae9.firebaseio.com/database.json'
postdata = { 'datetime': str(calendar.timegm(time.gmtime())), 'sensorId': "1", 'tempRecord': str(read_temp()) }
req = Request(url)
req.add_header('Content-Type','application/json')
data = json.dumps(postdata)
response = urlopen(req,data)
the error:
req = request(url) NameError: name 'request' is not defined
语句 from urllib.request import urlopen
仅导入 urlopen
。如果要调用 Request
,则需要专门导入 Request
,或者导入整个 urllib.request
模块(然后将 Request
调用为 urllib.request.Request
) .