Somethimes i got a error that the function call dont return graph_data["value"]
, so i tried put it inside a try except block and made a recursive call to the function.
But I am receiving
UnboundLocalError: local variable 'obj' referenced before assignment
I am using flask.
def get_chart_images(dam, chart_name, chart_path):
token = _get_token_from_cache(app_config.SCOPE)
if not token:
return redirect(url_for("login"))
url = "https://graph.microsoft.com/v1.0/" + chart_path + "/Image(width=800,height=600,fittingMode='fit')"
try:
graph_data = requests.get( # Use token to call downstream service
url,
headers={'Authorization': 'Bearer ' + token['access_token']},
).json()
obj = {
"dam": dam,
"chart_name": chart_name,
"chart_image": graph_data["value"]
}
except:
#trying call again the function
get_chart_images(dam, chart_name, chart_path)
return obj