Ниже приведен пример кода:
Код: Выделить всё
response = requests.get(url)
data = response.json()
if response.status_code!=200:
print(f"Error occurred for ID - Response code {response.status_code} {response.reason}")
break
if response.status_code==200:
df1 = pd.concat([df1, pd.json_normalize(data)])
else:
print(f'No data to fetch data for {reaction}:{id}')
if not df1.empty:
all_accounts_failed = False
if all_accounts_failed:
raise Exception("All API calls failed for all IDs")
raise
else:
try:
#rest of the code
Фрагмент из DAG
Подробнее здесь: https://stackoverflow.com/questions/793 ... ython-code
Мобильная версия