更新时间:2023-09-11 22:28:16
由于data
是unicode/str变量而引发此错误,请更改代码的第二行以解决错误:
This error raised because the data
is a unicode/str variable, change the second line of your code to resolve your error:
data = json.loads(data)
json.load
在第一个参数位置获取一个文件对象,并调用此对象的read
方法.
json.load
get a file object in first parameter position and call the read
method of this.
您还可以调用响应的json
方法直接获取数据:
Also you can call the json
method of the response to fetch data directly:
response = requests.get('http://ws.audioscrobbler.com/2.0/?method=library.getartists&api_key=4c22bd45cf5aa6e408e02b3fc1bff690&user=joanofarctan&format=json')
data = response.json()