在处理流处理程序callb时,Python请求不处理第二个get请求

2024-03-28 08:59:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Hacker News API找到here,特别是live data部分。你知道吗

我目前正在尝试打印从/v0/maxitemAPI获得的每个新项的响应。你知道吗

以下是我目前拥有的代码:

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值。你知道吗

但是GETURL在postman上工作,能够在那里得到有效的响应。问题似乎特别在于requests模块第二次是如何处理URL的。你知道吗

非常感谢您的帮助。你知道吗


Tags: importidconfigjsonmessagenewdatastream