coddingtonbear / python-myfitnesspal

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

Exception has occurred: IndexError list index out of range #156

Open quangvv9Life opened 1 year ago

quangvv9Life commented 1 year ago

Hi guys,

Recently, i have been tested out this package and got this error which i guess might be a new security mechanism from myfitnesspal :

Exception has occurred: IndexError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
list index out of range
  File "G:\0_9Health\6_data\python-myfitnesspal\.venv\Lib\site-packages\myfitnesspal-2.0.1-py3.10.egg\myfitnesspal\client.py", line 780, in get_food_search_results
    utf8_field = document.xpath("(//input[@name='utf8']/@value)[1]")[0]
  File "G:\0_9Health\6_data\python-myfitnesspal\src\search-foods.py", line 32, in <module>
    food_items = client.get_food_search_results(ingredient_name)
  File "C:\Users\9Health\.pyenv\pyenv-win\versions\3.10.6\Lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\9Health\.pyenv\pyenv-win\versions\3.10.6\Lib\runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
IndexError: list index out of range

here is my code :

...
ingredient_name = "Champ - Gourami Fish"
food_items = client.get_food_search_results(ingredient_name)

does you guys have the same problem as mine ?

realPrimoh commented 1 year ago

On line 780 of get_food_search_results in clent.py, replace 'utf8' with 'search'.

hannahburkhardt commented 1 year ago

Thanks @quangvv9Life and @realPrimoh - I fixed the issue in #159. Let me know if that fix does not fix the issue for you!