Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johnhillescobar opened this issue May 24, 2023 · 2 comments
Open

Comments

@johnhillescobar
Copy link

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
Copy link
Collaborator

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
Copy link

haemi commented Oct 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants