coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically
MIT License
789 stars 138 forks source link

Error when calling get_food_search_results("bacon cheeseburger") #158

Open johnhillescobar opened 1 year ago

johnhillescobar commented 1 year ago

Hi team,

I am developing a super simple webapp to better follow up my metrics and I found out this error when running the example in your documentation.

client.get_food_search_results("bacon cheeseburger")

IndexError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_38820\648193376.py in <module>
----> 1 client.get_food_search_results("bacon cheeseburger")

~\anaconda3\lib\site-packages\myfitnesspal\client.py in get_food_search_results(self, query)
    778             "(//input[@name='authenticity_token']/@value)[1]"
    779         )[0]
--> 780         utf8_field = document.xpath("(//input[@name='utf8']/@value)[1]")[0]
    781 
    782         result = self.session.post(

IndexError: list index out of range

Any suggestion for this error?

hannahburkhardt commented 1 year ago

Thanks John! Looks like the referenced element ('utf8') no longer exists in this page, and the search request (https://www.myfitnesspal.com/food/search) no longer expects it. It appears to be safe to remove. See PR #159

haemi commented 9 months ago

Hi, I still get an IndexError with 2.0.1:

import myfitnesspal
import browser_cookie3

client = myfitnesspal.Client(browser_cookie3.safari())

food_items = client.get_food_search_results("bacon cheeseburger")

Traceback (most recent call last):
  File "/Users/.../PycharmProjects/Strength/datakitchensink.py", line 11, in <module>
    food_items = client.get_food_search_results("bacon cheeseburger")
  File "/usr/local/lib/python3.9/site-packages/myfitnesspal/client.py", line 780, in get_food_search_results
    utf8_field = document.xpath("(//input[@name='utf8']/@value)[1]")[0]
IndexError: list index out of range