Я пытаюсь сохранить ответ от API в файл. Я использую для l oop.
headers = {'Accept-Encoding': 'gzip'}
keys = ["1", "11", "14", "10", "25"] # Parameter keys
#n=1
#k = keys[n]
#ATS - list containing station ids
response11 = list()
api_data = dict()
for x in keys:
for s in ATS:
r11 = requests.get("https://opendata-download metobs.smhi.se/api/version/latest/parameter/"+x+"/station/"+s+"/period/corrected-archive/data.csv", headers=headers)
#print(r11.status_code)
y = r11.status_code
if y == 404:
print("Parameter", x, "Station", s)
print("Station do not produce data for the specific parameter, requests points to a resource that does not exists")
continue
print("Status code", y, "Parameter", x, "Station", s)
#s = r11.text
response11.append(r11.text)
api_data.update({s: r11.text})
print (response11)
print (api_data)
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
in
21 print("Status code", y, "Parameter", x, "Station", s)
22 #s = r11.text
---> 23 response11.append(r11.text)
24 api_data.update({s: r11.text})
25
c:\python37\lib\site-packages\requests\models.py in text(self)
860 # Decode unicode from given encoding.
861 try:
--> 862 content = str(self.content, encoding, errors='replace')
863 except (LookupError, TypeError):
864 # A LookupError is raised if the encoding was not found which could
MemoryError:
Я получаю Ошибка памяти . Как я могу решить эту проблему? Каков наилучший способ легко сохранить ответ API в файле или списке, чтобы его можно было вызывать и использовать?
Любая помощь будет принята с благодарностью. Спасибо