我正在尝试从goodreads API获取json文件,但我的代码未读取该文件

时间:2018-12-30 15:34:45

标签: python json python-requests

它显示以下错误:

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

代码如下:

import requests
import json

res = requests.get("https://www.goodreads.com/book/review_counts.json", params={"key": "gmaVsowZsITzZGWKQjQ3sQ", "isbn": "0743269268"})
data=res.json()
print(data)

3 个答案:

答案 0 :(得分:1)

使用'isbns'代替'isbn',评论文件中没有名为'isbn'的参数

答案 1 :(得分:0)

您的示例返回422'未指定ISBN。请通过将isbn重命名为isbns来解决此问题

答案 2 :(得分:0)

用'isbns'替换参数中的'isbn'

import requests
import json
res = requests.get("https://www.goodreads.com/book/review_counts.json", params={"key": "gmaVsowZsITzZGWKQjQ3sQ", "isbns": "0743269268"})
print(res.text)
data=res.json()
print(data)

输出

{"books":[{"id":16183,"isbn":"0743269268","isbn13":"9780743269261","ratings_count":41973,"reviews_count":76642,"text_reviews_count":1914,"work_ratings_count":45888,"work_reviews_count":83363,"work_text_reviews_count":2194,"average_rating":"3.70"}]}
{'books': [{'isbn13': '9780743269261', 'work_ratings_count': 45888, 'isbn': '0743269268', 'id': 16183, 'work_text_reviews_count': 2194, 'reviews_count': 76642, 'average_rating': '3.70', 'work_reviews_count': 83363, 'text_reviews_count': 1914, 'ratings_count': 41973}]}