Radu-Raicea/Interesting-People-On-Medium

ValueError: No JSON object could be decoded

Closed this issue · 4 comments

python finder.py --name kordan --min-recommendations 10

Looking for interesting users for kordan...
Retrieving user ID...
Retrieving users from Followings...
Retrieving the latest posts...
Traceback (most recent call last):
  File "finder.py", line 188, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "finder.py", line 183, in main
    interesting_users = get_interesting_users(name, min_recommendations)
  File "finder.py", line 170, in get_interesting_users
    posts = get_list_of_latest_posts_ids(usernames)
  File "finder.py", line 70, in get_list_of_latest_posts_ids
    response_dict = clean_json_response(response)
  File "finder.py", line 14, in clean_json_response
    return json.loads(response.text.replace('])}while(1);</x>', '', 1))
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Hi @hitripod
I ran the script with your arguments and was able to successfully get a list of interesting users.

I suspect that your Internet connection dropped for a moment and the response was corrupted. Can you please try again?

Here is the list that was returned:

['perceptionsbyparker', 'tiedtiger', 'gutbloom', 'sourcePOV', 'creativeonion', 'TrukeLayser', 'helderluis', 'cjllewellyn', 'owenchien', 'justinbeswick', 'fisherlrp']

Closing this because of lack of response and issue is fixed.

Yes, it failed by chance.
I think the ValueError should be caught regardless of the quality of the connection. (i.e., handle the timeout)

#5

I will fix that soon!