Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54114

Another question about JSON

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <papillion@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'api.': 0.05; 'string.': 0.05; 'json': 0.07; 'pgp': 0.09; 'valueerror:': 0.09; 'subject:question': 0.10; '(just': 0.16; 'advance!': 0.16; 'fingerprint:': 0.16; 'obj,': 0.16; 'obviously': 0.18; 'bit': 0.19; 'trying': 0.19; 'everyone,': 0.19; 'print': 0.22; 'header :User-Agent:1': 0.23; '31,': 0.24; "i've": 0.25; 'skip:" 30': 0.26; 'code:': 0.26; 'skip:_ 20': 0.27; 'raise': 0.29; 'returned': 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'loads': 0.31; 'anyone': 0.31; 'file': 0.32; 'figure': 0.32; '(most': 0.33; "i'd": 0.34; 'could': 0.34; 'good.': 0.35; 'received:google.com': 0.35; 'skip:j 20': 0.36; 'done': 0.36; 'doing': 0.36; 'thanks': 0.36; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.61; '366,': 0.84; 'url:v1': 0.84; 'browser:': 0.91; 'trouble.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=DMXpmwUzQAetbO6XevbttKN54A35EMLM2f/vsB/yqlo=; b=soxnLC2KCQKvg5jspk5SKLZkMexSUaemCqYozDoNp6DhztBeOQoiULnyH4oyj/4yTk 6P8VPoeQfPhI+9emhSfhrqHIZFxF+GqG0EjENS/my5/vBpsrgk9hr2+5TrZ7RsVuqPv1 9zxCKerXhRPAe8vyxSTpaejJDIyKFQXWFxDORCnEpfc8MO7nmIjvcLWWYZ9jz7WY3o7c 8e7Tri19TpQE7WBzrVD9/emIiRtJiFodqh3hWwRT3a4yuoXy0t6kmIzG8hMKi6TR+V6W 5iZ7ybj6QavXKa/kEbGm5V7EjGcOf0ZEChCQP+/sQfvpcrYHfknqAADYCBYPveRKvoPi Cvgg==
X-Received by 10.50.25.101 with SMTP id b5mr1269065igg.31.1379077249753; Fri, 13 Sep 2013 06:00:49 -0700 (PDT)
Date Fri, 13 Sep 2013 08:00:47 -0500
From Anthony Papillion <papillion@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8
MIME-Version 1.0
To python-list@python.org
Subject Another question about JSON
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.355.1379077258.5461.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1379077258 news.xs4all.nl 15992 [2001:888:2000:d::a6]:41092
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54114

Show key headers only | View raw


Hello Again Everyone,

I'm still working to get my head around JSON and I thought I'd done so
until I ran into this bit of trouble. I'm trying to work with the
CoinBase API. If I type this into my browser:

https://coinbase.com/api/v1/prices/buy

I get the following JSON returned

{"subtotal":{"amount":"128.00","currency":"USD"},"fees":[{"coinbase":{"amount":"1.28","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"129.43","currency":"USD"},"amount":"129.43","currency":"USD"}

So far, so good. Now, I want to simply print out that bit of JSON (just
to know I've got it) and I try to use the following code:

returnedJSON = json.loads('https://coinbase.com/api/v1/prices/buy')
print returnedString

And I get a traceback that says: No JSON object could be decoded. The
specific traceback is:

Traceback (most recent call last):
  File "coinbase_bot.py", line 31, in <module>
    getCurrentBitcoinPrice()
  File "coinbase_bot.py", line 28, in getCurrentBitcoinPrice
    returnedString = json.loads(BASE_API_URL + '/prices/buy')
  File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded


I'm very confused since the URL is obviously returned a JSON string. Can
anyone help me figure this out? What am I doing wrong?

Thanks in advance!
Anthony


-- 
Anthony Papillion
XMPP/Jabber:      cypherpunk@patts.us
OTR Fingerprint:  4F5CE6C07F5DCE4A2569B72606E5C00A21DA24FA
SIP:              17772471988@callcentric.com
PGP Key:          0xE1608145

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Another question about JSON Anthony Papillion <papillion@gmail.com> - 2013-09-13 08:00 -0500
  Re: Another question about JSON John Gordon <gordon@panix.com> - 2013-09-13 14:35 +0000

csiph-web