People have a problem with this code:
def task_get_data_misindicadores():
url = 'https://*****.co/api/*****/{0}/'.format(
config.MI_APIKEY
)
req = requests.get(url)
if not req.ok:
return 'Timeout Error'
to_cache = []
try:
for indicator in req.json():
if indicator['updated_at'] is None:
continue
if indicator['is_public']:
updated_at = timesince(datetime.strptime(
indicator['updated_at'], "%Y-%m-%dT%H:%M:%S"
))
to_cache.append({
'name': indicator['name'],
'value': "{0:0.0f}".format(float(indicator['measured_value'])),
'url': 'https://*****.co{0}'.format(
indicator['url']
),
'trend': indicator['trend'],
'heat': indicator['heat'],
'metric_units': indicator['metric_units'],
'goal': indicator['goal'],
'updated_at': updated_at,
})
except TypeError:
pass
if len(to_cache) > 0:
cache.set('mis_indicadores_list', to_cache, 3600)
return True
return False
It turns out that whenever you get to the line for indicator in req.json():
throws the exception, I tried anyway to convert it to string but fail.
I use this inside a celery task, when I do it because shell_plus runs perfect but in celery it always fails.
I use:
Python 3.5
Any ideas on how to avoid this error?