1

My flask app keeps bringing up this error when I run the json request to an api, but it runs well from my terminal. What could be wrong? I've loked through the website but none of the solution is applicable. This is my code:

    import requests

    key = "XpVcEz3pf5hXpJ7psgasaszhMng"
    isbns = "2497573957X"

    res = requests.get("https://www.goodreads.com/book/review_counts.json",
                       params={"key": key, "isbns": isbns})
    goodreads = res.json()
    averageratings = goodreads["books"][0]["average_rating"]

And this is the json result I get from my terminal where I ran the code:

{'books': [{
                'id': 29207858,
                'isbn': '1632168146',
                'isbn13': '9781632168146',
                'ratings_count': 0,
                'reviews_count': 1,
                'text_reviews_count': 0,
                'work_ratings_count': 26,
                'work_reviews_count': 113,
                'work_text_reviews_count': 10,
                'average_rating': '4.04'
            }]
}
ncopiy
  • 1,515
  • 14
  • 30
  • Possible duplicate: https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0. – ngShravil.py May 18 '20 at 18:21
  • first format code in question - when you edit question use special button `{}` – furas May 18 '20 at 18:40
  • first use `print( res.text )` to see what you get from server when you use in Flask. Maybe you get error message with explanation. You can also check `print( res.status_code )`. Next check if you send correct parameters. – furas May 18 '20 at 18:42
  • do you run flask on the same computer as script in console? Some servers may blocks access to external servers to block spamers. – furas May 18 '20 at 18:45

0 Answers0