@app.route('/api/<string:isbn>', methods = ['GET'])
def isbn(isbn):
#import api from Goodreads (stats)
book_data = db.execute("SELECT * FROM books WHERE isbn=:isbn",{'isbn':isbn}).fetchone()
title = book_data['title']
author = book_data['author']
year = book_data['year']
res = requests.get("https://www.goodreads.com/book/review_counts.json", params={"key": "4RbGuzka0IUcJWWk1mivqg", "isbns":isbn }).json()
reviews_count = float(res['books'][0]['reviews_count'])
avg_score = float(res['books'][0]['average_rating'])
dic = {"title": title, "author":author, "year": year,"isbn":isbn,"reviews_count":reviews_count,"avg_score":avg_score}
print(dic)
return jsonify(dic)
can somebody please tell me what is wrong with this code, when i am specifying 10 characters isbn number it is giving me the right api. when the isbn number i specify is less than 10 characters i am getting internal server error as:
line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The upper version works. However with e.g. '756403146' you get the response "'No books match those ISBNs.'" (in result.text). Hence, the isbn is not in the database. If you try to .json() the result of those responses you get the error message you posted.