0

I am trying to parse json obtained from this api call: https://poloniex.com/public?command=returnTicker

But when I run the commands:

    print site_name
    site = urllib2.Request(site_name)

    response=urllib2.urlopen(site_name) 

    print response.read()

    t= json.loads(response.read())

I get:

https://poloniex.com/public?command=returnTicker
{"BTC_BCN":  ... (rest of json response)
ValueError: No JSON object could be decoded

I have validated the resulting json object using www.jsonlint.com and it is valid. What am I doing wrong?

1
  • You get a urllib2.HTTPError: HTTP Error 403: Forbidden error. Commented Jul 20, 2017 at 18:47

1 Answer 1

3

if you print response.read(), then the next time you try to read from it you'll get an empty string.

Empty string is not a valid json string.

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

2 Comments

This is one thing. All I get is a 403 error with urllib2. Works with requests. Did you try it? Edit: nvm, seems to work for OP.
No I didn't. Isn't there different versions of urllib2 and you're using one which is not that good? As you said, question shows that OP successfully prints some valid response, flushing the stream in the process :)

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.