coddingtonbear / python-myfitnesspal

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

myfitnesspal.Client('my_username') returns JSONDecodeError: Expecting value: line 1 column 1 (char 0) #66

Closed jojo9289 closed 6 years ago

jojo9289 commented 6 years ago

Hi,

first , my environment : Win10 Pro /anaconda 1.8.5 / python 3.6.4

After having stored my password with $myfitnesspal store-password my_username

the client connection with $client = myfitnesspal.Client('my_username') is returning below error and I cannot figure out what is wrong . Did you already experiment such error ?

thx in advance

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-21-3d3db237c829> in <module>()
      6 
      7 #Connection with my credentials
----> 8 client = myfitnesspal.Client('my_username')
      9 
     10 day = client.get_date(2018, 12, 3)

~\Anaconda3\lib\site-packages\myfitnesspal\client.py in __init__(self, username, password, login, unit_aware)
     50         self.session = requests.Session()
     51         if login:
---> 52             self._login()
     53 
     54     @property

~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _login(self)
    103             )
    104 
--> 105         self._auth_data = self._get_auth_data()
    106         self._user_metadata = self._get_user_metadata()
    107 

~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _get_auth_data(self)
    124             )
    125 
--> 126         return result.json()
    127 
    128     def _get_user_metadata(self):

~\Anaconda3\lib\site-packages\requests\models.py in json(self, **kwargs)
    890                     # used.
    891                     pass
--> 892         return complexjson.loads(self.text, **kwargs)
    893 
    894     @property

~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    352             parse_int is None and parse_float is None and
    353             parse_constant is None and object_pairs_hook is None and not kw):
--> 354         return _default_decoder.decode(s)
    355     if cls is None:
    356         cls = JSONDecoder

~\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

~\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
--> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
    358         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
coddingtonbear commented 6 years ago

I haven't seen such an error before, but it does look like the problem is probably rooted somewhere in authentication. Things I'd check are probably:

  1. Are you sure you used the right username and password?
  2. Are you sure the script was sending the right username and password? You could investigate that by strategically inspecting things using pdb around here: ~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _login
  3. Maybe the response isn't quite what we're expecting; you might want to look at what result.content is here: ~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _get_auth_data

Good luck, and let me know if you need any other debugging tips; feel free to ask me questions on the gitter channel, too.

jojo9289 commented 6 years ago

Solved ! It was due to a change of Privacy/ T&Cs in MFP which was pop up only in the web version . Once I hit the « consent » button, the API was back , behaving normally. Thx .

Le 30 mai 2018 à 23:09, Adam Coddington notifications@github.com<mailto:notifications@github.com> a écrit :

I haven't seen such an error before, but it does look like the problem is probably rooted somewhere in authentication. Things I'd check are probably:

  1. Are you sure you used the right username and password?
  2. Are you sure the script was sending the right username and password? You could investigate that by strategically inspecting things using pdb around here: ~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _login
  3. Maybe the response isn't quite what we're expecting; you might want to look at what result.content is here: ~\Anaconda3\lib\site-packages\myfitnesspal\client.py in _get_auth_data

Good luck, and let me know if you need any other debugging tips; feel free to ask me questions on the gitter channel, too.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/coddingtonbear/python-myfitnesspal/issues/66#issuecomment-393320170, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Al6x9Kd3EJz-pJZoRJ2017BC0eRORyrWks5t3wqAgaJpZM4US0yz.

coddingtonbear commented 6 years ago

Awesome; I'm glad you figured it out!