@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)
有人可以告诉我这段代码有什么问题吗,当我指定 10 个字符的 isbn 数字时,它给了我正确的 api。当我指定的 isbn 编号少于 10 个字符时,我收到内部服务器错误:
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)