json - strange python issue, 'unicode' object has no attribute 'read' -
here code , have ideas wrong? open my json content directly browser , works,
data = requests.get('http://ws.audioscrobbler.com/2.0/?method=library.getartists&api_key=4c22bd45cf5aa6e408e02b3fc1bff690&user=joanofarctan&format=json').text data = json.load(data) print type(data) return data
thanks in advance, lin
this error raised because data
unicode/str variable, change second line of code resolve error:
data = json.loads(data)
json.load
file object in first parameter position , call read
method of this.
also can call json
method of response 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()
Comments
Post a Comment