3

I'm getting an error when I execute this script and can't figure it out.

The Error:

Traceback (most recent call last):
  File "./upload.py", line 227, in <module>
    postImage()
  File "./upload.py", line 152, in postImage
    reddit = RedditConnection(redditUsername, redditPassword)
  File "./upload.py", line 68, in __init__
    self.modhash = r.json()['json']['data']['modhash']
  File "/usr/lib/python2.6/site-packages/requests/models.py", line 799, in json
    return json.loads(self.text, **kwargs)
  File "/usr/lib/python2.6/site-packages/simplejson/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.6/site-packages/simplejson/decoder.py", line 335, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.6/site-packages/simplejson/decoder.py", line 353, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
5
  • Possible duplicate of Python No JSON object could be decoded Commented Jun 17, 2015 at 4:08
  • I found that thread but don't see how it can help me. I have the validator open, but in my case, I don't know what to paste. Commented Jun 17, 2015 at 4:12
  • Can you just print the JSON out into the console? Also, I believe your code has information you probably shouldn't share... imgurClientId / imgurClientSecret Commented Jun 17, 2015 at 5:16
  • I can if you can tell me how, I really don't know how I can. The machine is on CentOS 7. I can type in anything you suggest. Standing by... thank you. Commented Jun 17, 2015 at 5:19
  • as @Guy3000 mentioned, you shouldn't post your api keys. I would probably reset your keys right away if I were you. Commented Jun 17, 2015 at 5:45

1 Answer 1

5

You are getting this exception because you are using the wrong json function here:

def getNumberOfFailures(path):
try:
    with open(path + '.failurecount') as f:
        return json.loads(f.read())
except:
    return 0

You need to do this instead:

def getNumberOfFailures(path):
    try:
        with open(path + '.failurecount') as f:
            return json.load(f)
    except:
        return 0

json.loads() is used on json strings. json.load() is used on json file objects.

As some people have mentioned, you need to reissue yourself a new API key and delete the one you posted here in your code. Other people can and will abuse those secret keys to spam Reddit under your name.

Sign up to request clarification or add additional context in comments.

1 Comment

I replaced that section with your updated version and also edited the above total script so that it reflects your changes. I ran it, and have the same error. Also the API secret above is just random keystrokes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.