首页 > 解决方案 > 需要帮助使用 firebase 流式休息 api 不起作用

问题描述

我试图从我的 firebase 数据库中流式传输更改,但我编写的代码似乎不起作用。它不会产生错误,流不会关闭,因为它一直在运行,直到我取消程序,但它不仅仅是产生任何结果。它没有显示对我的数据的任何更改。我尝试将不同的数据发布到数据库以查看流是否会更新但不会更新。如果我删除它可以工作但它没有流式传输的标题,我只需获取一次数据并关闭它。下面是我的代码。不感谢帮助


import requests
import json

headers = {"Accept": "text/event-stream"}
r = requests.get("https://************************************/messages/*******.json", stream= True, headers=headers, allow_redirects=True)

if r.encoding is None:
   r.encoding = 'utf-8'

for line in r.iter_lines(decode_unicode=True):
   if line:
       print(json.loads(line))

我按照本页底部的说明https://firebase.google.com/docs/database/rest/retrieve-data。提前致谢

标签: pythonfirebasefirebase-realtime-databasepython-requests

解决方案


推荐阅读