coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically
MIT License
796 stars 139 forks source link

client.get_measurements not working #186

Open natesanshreyas opened 2 weeks ago

natesanshreyas commented 2 weeks ago

Hey all,

I've had a great experience getting macros out of MFP via the MFP library, but getting weight (via get_measurements) has been really difficult for me. I'll be able to get weight for a day or so and then I'll hit this issue:

Traceback (most recent call last): File "/Users/shreyasnatesan/Documents/python/get_weight.py", line 7, in weight = client.get_measurements("Weight") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shreyasnatesan/Desktop/NucampFolder/Python/1-Fundamentals/myenv/lib/python3.12/site-packages/myfitnesspal/client.py", line 615, in get_measurements measurement_ids = self._get_measurement_ids(document) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/shreyasnatesan/Desktop/NucampFolder/Python/1-Fundamentals/myenv/lib/python3.12/site-packages/myfitnesspal/client.py", line 741, in _get_measurement_ids for q in next_data_json["props"]["pageProps"]["dehydratedState"]["queries"]:


KeyError: 'dehydratedState'

Using scripts inclusive of what we see here: 

import myfitnesspal
import browser_cookie3
from datetime import date,timedelta

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

weight = client.get_measurements("Weight")
print(weight)

I'm not sure what I'm doing wrong or if this is an issue with the library itself...
ColorfulQuark commented 1 week ago

That happens to me periodically. Logging out, clearing cookies and trying a couple of times usually works (or wastes time while the problem fixes itself). It's probably and issue with MFP rather than you or the library.