0

I am trying to play with the Hacker News API found here, especially the live data section.

I am currently trying to print the response I get for every new item that I get from the /v0/maxitem API.

Given below is the code that I currently have:

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")

I am able to get a valid response the first time requests.get runs. But the second time, I always get a NULL value for the content of the response.

The GET URL works on postman though, able to get a valid response there. The issue seems to particularly be with how the requests module is treating the URL the second time.

Any help greatly appreciated.

Zoe
  • 27,060
  • 21
  • 118
  • 148
lordlabakdas
  • 1,163
  • 5
  • 18
  • 33

0 Answers0