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=06031&parameterId=temp_dry&datetime=2021-01-01T00:00:00Z/2021-03-01T00:00:00Z&api-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.


1 Answer 1


This is not a data science question and you should try programming stack-exchange instead. But this is happening because of an API mismatch in Python, specifically the type of the GET method of the requests object. It's likely the code snippet you got is from a version that is not python 3.2 or a requests module that is not up to date. I would try to install a compatible version of the requests module from PyPI or make your python version compatible with the snippet.

  • 1
    $\begingroup$ Alright, I'll ask in programming instead, is that the stack overflow? Still, thank you for your answer. $\endgroup$
    – L. Nielsen
    Commented Apr 20, 2021 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.