coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Saving measurements fails

iakovmarkov opened this issue · comments

commented

Hi all!

I'm running into a weird error when trying to save measurements (weight) into MFP. The command fails without much output. When I've enabled debugging of requests module, I've found out that MFP returns a redirect to login page instead of saving data and redirecting back to measurements.

I've added some debug logs to your code to see what happens. It looks something like this:

INFO:root:Logging in
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.myfitnesspal.com:443
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET /account/login HTTP/1.1" 200 None
ERROR:__main__:_get_content_for_url
ERROR:__main__:_mfp_session: %SNIP%
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "POST /account/login HTTP/1.1" 302 None
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET /en/ HTTP/1.1" 302 95
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET / HTTP/1.1" 200 None
ERROR:__main__:_LOGIN
ERROR:__main__:_mfp_session: %SNIP%
ERROR:__main__:session_event_session_start_website_195169222578109: true
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET /user/auth_token?refresh=true HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.myfitnesspal.com:443
DEBUG:urllib3.connectionpool:https://api.myfitnesspal.com:443 "GET /v2/users/%SNIP%?fields%5B%5D=diary_preferences&fields%5B%5D=goal_preferences&fields%5B%5D=unit_preferences&fields%5B%5D=paid_subscriptions&fields%5B%5D=account&fields%5B%5D=goal_displays&fields%5B%5D=location_preferences&fields%5B%5D=system_data&fields%5B%5D=profiles&fields%5B%5D=step_sources HTTP/1.1" 200 1183
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET /measurements/edit?page=1&type=1 HTTP/1.1" 200 None
ERROR:__main__:_get_content_for_url
ERROR:__main__:_mfp_session: %SNIP%
INFO:__main__:OrderedDict([(datetime.date(2020, 9, 15), 11.0), (datetime.date(2020, 9, 13), 20.0), (datetime.date(2020, 9, 11), 14.0), (datetime.date(2020, 9, 1), 1.0), (datetime.date(2020, 8, 31), 84.0), (datetime.date(2016, 2, 21), 87.5), (datetime.date(2015, 8, 8), 90.0), (datetime.date(2015, 7, 13), 90.0)])
WARNING:__main__:https://www.myfitnesspal.com/measurements/new
WARNING:__main__:{'utf8': '%E2%9C%93', 'authenticity_token': '%SNIP%', 'type': '1', 'profile[initial_weight_date(2i)]': '8', 'profile[initial_weight_date(3i)]': '31', 'profile[initial_weight_date(1i)]': '2020', 'initial_weight[display_value]': '84', 'measurement[entry_date(2i)]': 9, 'measurement[entry_date(3i)]': 15, 'measurement[entry_date(1i)]': 2020, 'measurement[display_value]': 50}
WARNING:__main__:{'known_user': '%SNIP%', '_mfp_session': '%SNIP%', 'session_event_session_start_website_195169222578109': 'true'}
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "POST /measurements/new HTTP/1.1" 302 108
DEBUG:urllib3.connectionpool:https://www.myfitnesspal.com:443 "GET /account/login HTTP/1.1" 200 None

Any idea what might cause this?

Hello,

Did you ever resolve this? I may be having a similar issue, if it's not the same let me know and I'll create a new bug.

Code:
import myfitnesspal
client = myfitnesspal.Client('username', password='password')
print(client.set_measurements(measurement="Weight",value=weight))

Output:
None
<class 'set'>

Result: The above output and no changes to MFP.

commented

Hi @JeffWDH. I wasn't able to solve this unfortunately.

I believe this is fixed via #129 , but let me know if this is still an issue.