pythonjsondecodeoembed

Why am I receiving this JSON Decode Error?


Here's what I'm doing.

I'm sending a get request to a reddit oembed endpoint. I want to parse the returned json and grab the raw html to embed a reddit post onto my django page. The error I receive when I try to do this is

json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

Here's an example of that code in action. (It's inside a function)

 endpoint = requests.get("https://www.reddit.com/oembed?url=https://www.reddit.com/r/nba/comments/n6l2zu/the_crew_lock_in_their_predictions_and_ernie_has/")

 return endpoint.json()['html']

Here is the html it should return. I'm thinking maybe I have to reformat it? Could someone help me out here? Thanks!

 '\n    <blockquote class="reddit-card" >\n      <a href="https://www.reddit.com/r/nba/comments/n6l2zu/the_crew_lock_in_their_predictions_and_ernie_has/?ref_source=embed&amp;ref=share">The crew lock in their predictions and Ernie has the Jazz going to the Finals</a> from\n      <a href="https://www.reddit.com/r/nba/">nba</a>\n    </blockquote>\n    <script async src="https://embed.redditmedia.com/widgets/platform.js" charset="UTF-8"></script>\n'

EDIT:

Here is the result of printing endpoint.json()

    {
   "provider_url":"https://www.reddit.com/",
   "version":"1.0",
   "title":"The crew lock in their predictions and Ernie has the Jazz going to the Finals",
   "provider_name":"reddit",
   "type":"rich",
   "html":"\n    <blockquote class=\"reddit-card\" >\n      <a href=\"https://www.reddit.com/r/nba/comments/n6l2zu/the_crew_lock_in_their_predictions_and_ernie_has/?ref_source=embed&amp;ref=share\">The crew lock in their predictions and Ernie has the Jazz going to the Finals</a> from\n      <a href=\"https://www.reddit.com/r/nba/\">nba</a>\n    </blockquote>\n    <script async src=\"https://embed.redditmedia.com/widgets/platform.js\" charset=\"UTF-8\"></script>\n",
   "author_name":"tanookiben"
}

Solution

  • I wasn't sending a proper header. Kept getting a 429 error back, and because there was no json returned, I was receiving the json decoder error.