Title: Kraken API: "ValueError: No JSON object could be decoded" Post by: rothj on July 09, 2017, 12:00:41 AM I'm working with the Kraken API to pull OHLC data and am receiving the following error in some of my API requests:
"Traceback (most recent call last): File "/Users/someone/anaconda/lib/python2.7/site-packages/krakenex/api.py", line 83, in _query return json.loads(ret) File "/Users/someone/anaconda/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/Users/someone/anaconda/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/someone/anaconda/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" Can anyone advise me on how to avoid this error? Thanks! Jake Title: Re: Kraken API: "ValueError: No JSON object could be decoded" Post by: pooya87 on July 09, 2017, 03:38:01 AM you have to post the code that you used, or at least the value that passed in that code as the JSON data not the exception that was thrown.
my guess is you passing something that is not a JSON as a JSON to your code which is why it can not decode it. break down your code to where you are passing that JSON in and see what the real value is. this is what that JSON should look like: https://api.kraken.com/0/public/OHLC?pair=XBTUSD&interval=1440 Title: Re: Kraken API: "ValueError: No JSON object could be decoded" Post by: rothj on July 30, 2017, 04:06:39 AM Thanks, sorry, I missed seeing your response.
Two things: (1) error message ```python Traceback (most recent call last): . . . File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/site-packages/krakenex/api.py", line 148, in query_public return self._query(urlpath, req, conn) File "/MYUSER/anaconda/envs/python3/lib/python3.5/site-packages/krakenex/api.py", line 131, in _query return json.loads(ret) File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ``` (2) my code (using the krakenex Python3 API: https://github.com/veox/python3-krakenex) ```python import krakenex k = krakenex.API() # instantiate API object pair = ["DASHEUR", "XETHZCAD"] # and some others; these just shown as example k.query_public(method="Ticker", req={"pair":pair}) # make public queries to Kraken ``` Title: Re: Kraken API: "ValueError: No JSON object could be decoded" Post by: locked_in on July 30, 2017, 04:34:04 AM Un-fucking-believable that Kraken would actually return the error to you instead of a regular plain 400 or 500 error.
They actually returned a Python exception to you? Title: Re: Kraken API: "ValueError: No JSON object could be decoded" Post by: Rannasha on July 30, 2017, 07:55:15 AM Un-fucking-believable that Kraken would actually return the error to you instead of a regular plain 400 or 500 error. They actually returned a Python exception to you? No, the Python errors shown are from the client-side. Kraken typically returns a JSON with the appropriate error message if something goes wrong. @OP: It seems that something in the response message doesn't parse correctly in the JSON decoder. So take a look at the raw response message, not the Python error message, (or post it here) to see what's going on. |