Open ryaustin opened 9 months ago
Seem to be running into an issue where the following has stopped returning any results:
results_name = r.json().get('foods')[0].get('description')
I added some code to the end of the program to create a dictionary I could append...
Unchanged code (for reference) from earlier in program:
search_endpoint = 'https://api.nal.usda.gov/fdc/v1/foods/search'
DEMO_KEY = 'DEMO_KEY'
r = requests.get(search_endpoint, params={"query": search, "api_key":DEMO_KEY})
results_name = r.json().get('foods')[0].get('description')
results_nutrients = r.json().get('foods')[0].get('foodNutrients')
New code:
ingredients = {'foodname':[], 'nutrients':[]}
if st.button:
ingredients['foodname'].append(results_name)
ingredients['nutrients'].append(results_nutrients)
st.write('My list:')
st.write(ingredients)
The code worked when I searched for a food and tried to add it. When I tried to add the same food a second time, the code I wrote above stopped working (even when I reloaded the page, and put #'s next to all the new code). I keep getting the following error:
Any thoughts? It's weird that that particular piece of code would generate the error, since it's been working fine up until now - and since it shouldn't be connected to the dictionary I tried to create. (I initially thought it might be that we'd exceeded the DEMO_KEY, but it didn't work even when I put my API key in.) Maybe I'll just try again later? Any thoughts appreciated!
Ignore that! Figured it out - using the command line!! That's a weekly win. Will reach out if I have any other questions!