KartikTalwar/Duolingo

JSON Extra data error on initial request

bobtista opened this issue · 2 comments

Could it be that the object has multiple top level objects and is bad JSON? I'm able to visit https://www.duolingo.com/users/ with my browser and get a JSON object back there with my data... and I pasted it in a json pretty printer and it seems fine there...

lingo  = duolingo.Duolingo('<username>')
  File "/usr/local/lib/python3.7/site-packages/duolingo.py", line 36, in __init__
    self.user_data = Struct(**self._get_data())
  File "/usr/local/lib/python3.7/site-packages/duolingo.py", line 177, in _get_data
    get = self._make_req(self.user_url).json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

I think you should provide password as the second parameter. I had the same issue when I called the function with just my username. This was resolved when I provided password too.

Could it be that the object has multiple top level objects and is bad JSON? I'm able to visit https://www.duolingo.com/users/ with my browser and get a JSON object back there with my data... and I pasted it in a json pretty printer and it seems fine there...

lingo  = duolingo.Duolingo('<username>')
  File "/usr/local/lib/python3.7/site-packages/duolingo.py", line 36, in __init__
    self.user_data = Struct(**self._get_data())
  File "/usr/local/lib/python3.7/site-packages/duolingo.py", line 177, in _get_data
    get = self._make_req(self.user_url).json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

Because it's authenticated using cookies stored in the web browser, try to do the same in an incognito window, or log out from Duolingo and check if you get a result. There is actually a way to get info while not being authenticated, but the code needs to be changed. There are different URLs for authenticated and nonauthenticated requests.