【发布时间】:2016-07-31 09:33:31
【问题描述】:
我是 Python 新手,我想使用 Python 连接到 Firebase。我可以使用 put() 和 patch() 成功添加和修改 Firebase,但我找不到从 Firebase 检索数据的方法。
代码:
import serial
import time
import requests
import json
firebase_url = 'https://testing1639.firebaseio.com'
#Connect to Serial Port for communication
ser = serial.Serial('/dev/ttyUSB0', 9600)
#Setup a loop to send temperature values at fixed intervals in seconds
fixed_interval = 2
while 1:
try:
#Temperature value obtained from Arduino + LM35 Temp Sensor
temperature_c = ser.readline()
#Current time and date
time_hhmmss = time.strftime('%H:%M:%S')
date_mmddyyyy = time.strftime('%d/%m/%Y')
#Current location name
temperature_location = 'Mumbai-Kandivali' ;
print temperature_c + ',' + time_hhmmss + ',' + date_mmddyyyy + ',' + temperature_location
#Insert record
data = {'date':date_mmddyyyy,'time':time_hhmmss,'value':temperature_c}
result = requests.post(firebase_url + '/' + temperature_location + '/temperature.json', data=json.dumps(data))
#Insert record
print 'Record inserted. Result Code = ' + str(result.status_code) + ',' + result.text
time.sleep(fixed_interval)
except IOError:
print('Error! Something went wrong.')
time.sleep(fixed_interval)
如何修改它以检索数据?
【问题讨论】:
-
有几个常用的库。请参阅 ozgur.github.io/python-firebase 和 github.com/mikexstudios/python-firebase。两者都在这里提到firebase.com/docs/rest/quickstart.html。如果您对他们有疑问,请发布您尝试过的内容,我们可以提供更好的帮助。
-
我会试试看。非常感谢您的回复
-
嗨,你有没有让你的 python 脚本在没有库的情况下工作?这些库的问题是它们已经过时了。现在,firebase 技术人员表示他们对那个特定的库有疑问。所以我认为直接从python访问他们的rest api会更安全。
标签: python get firebase python-requests patch