我正在尝试使用Hacker News API找到here,特别是live data部分。你知道吗
我目前正在尝试打印从/v0/maxitem
API获得的每个新项的响应。你知道吗
以下是我目前拥有的代码:
import pyrebase
from config import config
import requests
firebase = pyrebase.initialize_app(config)
firebase_db = firebase.database()
_BASEURL_ = "https://hacker-news.firebaseio.com/v0/item/"
def print_response(id):
headers = {"Content-Type": "application/json"}
print(_BASEURL_ + str(id) + ".json")
response = requests.get(_BASEURL_ + str(id) + ".json", headers=headers)
print(response.content)
def new_post_handler(message):
print(message["data"])
print_response(message["data"])
my_stream = firebase_db.child("/v0/maxitem").stream(new_post_handler,
stream_id="new_posts")
我能够在requests.get
第一次运行时得到有效的响应。但是第二次,我总是得到响应内容的NULL
值。你知道吗
但是GET
URL在postman上工作,能够在那里得到有效的响应。问题似乎特别在于requests
模块第二次是如何处理URL的。你知道吗
非常感谢您的帮助。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐