coddingtonbear / python-myfitnesspal

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

Recent MyFitnessPal changes prevent this library from logging-in #128

Closed uccollab closed 2 years ago

uccollab commented 2 years ago

For an hour or so I'm unable to log in with the library due to an index error in the client.py file. (I'm working on a Linux VM) I'm perfectly able to get inside the account from a mobile phone, website etc... even on the VM. I've found a similar previous issue but the suggestion (logging and accepting eventual popups) didn't work.

File "/home/virtual/Desktop/updated_version/stable/data_handling_layer/__init__.py", line 32, in handle_client client = mfp.Client(user_name, password) File "/home/virtual/.local/lib/python3.8/site-packages/myfitnesspal/client.py", line 69, in __init__ self._login() File "/home/virtual/.local/lib/python3.8/site-packages/myfitnesspal/client.py", line 104, in _login authenticity_token = document.xpath( IndexError: list index out of range

shelleyhowarth commented 2 years ago

I'm experiencing the same issue right now

coddingtonbear commented 2 years ago

We're, unfortunately, at the mercy of any changes that the folks at myfitnesspal might make to their UI, and just briefly glancing at your traceback, it looks like they've moved where they're storing the authenticity token in the DOM. Looking at the content of the page now, I do see that an authenticity token is still present on the page somewhere; it's probably just at a different path.

I'll try to take a look at this in the next few days, but if any of you has the time to post a PR updating that xpath query to point at the right spot, I'd be glad to merge that fix and we'd get to a solution a little faster than otherwise.

akcode47 commented 2 years ago

@coddingtonbear I don't see the authenticity_token named input within the HTML string of the content variable within the _get_document_for_url method.

When you log in via web browser, the input is visible in the HTML post refresh.

If we remove the index and view the authenticity_token variable in the _login method - it returns an empty list, so this seems to indicate you may need to refresh the session to get the latest HTML document. I'm not sure if that is possible - I need to look into it later.

coddingtonbear commented 2 years ago

I spent an hour looking into this this evening, and I'm afraid to say that it looks like parts of the authentication flow have changed, and adapting the library to those changes doesn't look like it'll be trivial. I did give it a shot, though, and I've begun the work of updating things in the branch 128_fixing_for_upstream_mfp_changes, but it's not likely I'll find enough time to fix this in the coming weeks. Hopefully somebody in the community can find a little time to look into it faster than I'm able to!

coddingtonbear commented 2 years ago

Earlier today @hannahburkhardt submitted a patch that solved this; thanks for solving this for us, @hannahburkhardt!