Reading a json-file from an API, getting "AttributeError: 'Response' object has no attribute 'data' "error
Title says it all. Im trying to read a json file im accessing via an API. But when I try, I get the error:
'AttributeError: 'Response' object has no attribute 'data'
I don't understand why, as most (not all) of my fellow classmates do not get this error.
The code I'm trying to run:
[1] import folium
[2] import geopandas as gpd
[3] import pandas as pd
[4] import numpy as np
[5] import urllib3
[6] import requests
[7] import json
[8] import os
[9] dmi_api = 'f8654190-89bb-43d2-9e08-416346b79e7b'
[10] url = 'https://dmigw.govcloud.dk/v2/metObs/collections/observation/itemsstationId=06031parameterId=temp_drydatetime=2021-01-01T00:00:00Z/2021-03-01T00:00:00Zapi-key='+str(dmi_api)
[11] r = requests.get(url)
[12] print(r)
[13] print(url)
[14] data = json.loads(r.data.decode('utf-8')) #This is where the error is referring to (which leads back to line 11)
[15] data
What I don't understand is why the json.loads
isnt working, as the link is obviously full of data.
I'm coding in Python 3.2 using the Jupyter Notebook accessed from Anaconda, if that's any help.
Category Data Science