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

Get_report broken? (JSONDecodeError) #177

Open
guidoderam opened this issue Mar 10, 2024 · 2 comments
Open

Get_report broken? (JSONDecodeError) #177

guidoderam opened this issue Mar 10, 2024 · 2 comments

Comments

@guidoderam
Copy link

I tried calling get_report in a couple of different ways but all of them resulted in a JSONDecodeError.

I looked at the relevant code and compared it to the API calls made on https://www.myfitnesspal.com/reports:

MFP reports page: https://www.myfitnesspal.com/api/services/reports/results/nutrition/fat/30?report_name=fat
Python-myfitnesspal get_report: https://www.myfitnesspal.com/reports/results/fat/30.json

Is get_report calling an old API? It takes 2 dates where the MFP reports page only uses a number of days from today. And the urls look different, but maybe there is some python/library magic going on (no Python expert!)?

@hannahburkhardt
Copy link
Collaborator

Hi @guidoderam, you're right, it looks like the URL has changed and so has the response format. However, the number of date arguments has not changed - it looks like we use only the lower_bound argument in the API call, then drop anything out of bounds before returning.

@haejinjo
Copy link

haejinjo commented Feb 12, 2025

I'm still seeing this issue

# try:
#     response = client.get_report("Net Calories", "Nutrition", end_date, start_date)
#     print(f"Raw response: {response}")  # Print raw response
# except Exception as e:
#     print(f"Error: {e}")

Date	Monday       Tuesday      Wednesday    Thursday     Friday       Saturday     Sunday       
----------------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "python-myfitnesspal/mfp.py", line 28, in <module>
    client.get_report("Net Calories", "Nutrition", end_date, start_date)
  File "/python-myfitnesspal/myfitnesspal/client.py", line 798, in get_report
    json_data = self._get_json_for_url(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "python-myfitnesspal/myfitnesspal/client.py", line 293, in _get_json_for_url
    return json.loads(content)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 356, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

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