Riak Problem w/ Python Client "No JSON object could be decoded"

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
Ive been trying for a few days now to fix this, ive tried every single format ive seen in examples online and put a JSON approved object as a string (used several JSON validation sides to check) in and i continually get this message.

Can anyone give me some seggestions?

Module riakcontrol:128 in search
>>  for r in query.reduce_sort().reduce_limit(5).run():
Module riak.mapreduce:211 in run
>>  result = t.mapred(self._inputs, query, timeout)
Module riak.transports.http:221 in mapred
>>  result = json.loads(response[1])
Module json:326 in loads
>>  return _default_decoder.decode(s)
Module json.decoder:360 in decode
>>  obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Module json.decoder:378 in raw_decode
>>  raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
extra data
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

Bob Ippolito
On Sat, Aug 20, 2011 at 4:10 PM, idmartin <[hidden email]> wrote:

> Ive been trying for a few days now to fix this, ive tried every single format
> ive seen in examples online and put a JSON approved object as a string (used
> several JSON validation sides to check) in and i continually get this
> message.
>
> Can anyone give me some seggestions?
>
> Module riakcontrol:128 in search
>>>  for r in query.reduce_sort().reduce_limit(5).run():
> Module riak.mapreduce:211 in run
>>>  result = t.mapred(self._inputs, query, timeout)
> Module riak.transports.http:221 in mapred
>>>  result = json.loads(response[1])
> Module json:326 in loads
>>>  return _default_decoder.decode(s)
> Module json.decoder:360 in decode
>>>  obj, end = self.raw_decode(s, idx=_w(s, 0).end())
> Module json.decoder:378 in raw_decode
>>>  raise ValueError("No JSON object could be decoded")
> ValueError: No JSON object could be decoded
> extra data

It would probably help diagnose your problem if you specified exactly
what code you were inserting data with and what that data looks like.
That's probably where the problem is.

I don't know the specifics of that riak client but you can look at
what's coming through if you run that under pdb.
http://docs.python.org/library/pdb.html

First start Python in interactive mode:
$ python -i yourscript.py

then when it prints the traceback and kicks you to the interactive
prompt you should load pdb in post-mortem mode:

>>> import pdb; pdb.pm()

From there you can navigate up the stack (with the "up" command) and
print out response[1] (with "p response[1]") to see what it is. You
may want to look at the repr of response[1] to be sure it is what you
think it is.

-bob

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
This post was updated on .
Bob,

Thanks for your response,

My code is buried deep within a WSGI based website making if difficult to debug this way. I have copied "code for code" from the tutorial posted with version 1.3 of the python client.

Here is a snippit of the function

        def search( self, bu, query ):
               
                if not self.bucket[bu].search_enabled(): #self.bucket --> riak buckets
                        self.bucket[bu].enable_search()
               
                query = self.client.search(bu , 'david') # self.client --> riak cleint

                                                                    # have tried a variety of search queries several taken from different tutorials,
                 
                data = {}
               
                for r in query.reduce_sort().reduce_limit(5).run():
                       
                        s = r.get()
                       
                        data.append(s.get_data())
                               
                return data
 
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

Jonathan Langevin
Have you browsed the actual content available in the bucket that you're querying, to verify it exists as you expect?
i.e.:

Browsing the data often reveals issues to me I didn't expect, such as when I first started testing with Riak, I was passing the wrong data type for json objects, so browsing to my object on Riak forced the browser to download the file instead of rendering json to the page, which let me know it wasn't seeing the object as proper json...


Jonathan Langevin
Systems Administrator

Loom Inc.
Wilmington, NC: (910) 241-0433 - [hidden email] - www.loomlearning.com - Skype: intel352



On Sun, Aug 21, 2011 at 3:40 PM, idmartin <[hidden email]> wrote:
Bob,

Thanks for your response,

My code is buried deep within a WSGI based website. I have copied "code for
code" from the tutorial posted with version 1.3 of the python client.

Here is a snippit of the function

       def search( self, bu, query ):

               if not self.bucket[bu].search_enabled(): #self.bucket --> riak buckets
                       self.bucket[bu].enable_search()

               query = self.client.search(bu , 'david') # self.client --> riak cleint

               data = {}

               for r in query.reduce_sort().reduce_limit(5).run():

                       s = r.get()

                       data.append(s.get_data())

               return data


--
View this message in context: http://riak-users.197444.n3.nabble.com/Riak-Problem-w-Python-Client-No-JSON-object-could-be-decoded-tp3271810p3273394.html
Sent from the Riak Users mailing list archive at Nabble.com.

_______________________________________________


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
Jon,

Thanks alot... this seems to be the problem. When i navigate to JSON files under 127.0.0.1 i get prompted to download.

How did you fix this?

Thanks,
Ian
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

Jonathan Langevin
Ensure your content type header your json objects is set to:
Content-Type: application/json

I believe when this occurred for me, I may have had something along the lines of text/json being passed, which wasn't correct.


Jonathan Langevin
Systems Administrator

Loom Inc.
Wilmington, NC: (910) 241-0433 - [hidden email] - www.loomlearning.com - Skype: intel352



On Tue, Aug 23, 2011 at 7:48 PM, idmartin <[hidden email]> wrote:
Jon,

Thanks alot... this seems to be the problem. When i navigate to JSON files
under 127.0.0.1 i get prompted to download.

How did you fix this?

Thanks,
Ian

--
View this message in context: http://riak-users.197444.n3.nabble.com/Riak-Problem-w-Python-Client-No-JSON-object-could-be-decoded-tp3271810p3279642.html
Sent from the Riak Users mailing list archive at Nabble.com.

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

TJ Ninneman
In reply to this post by idmartin
>
> Thanks alot... this seems to be the problem. When i navigate to JSON files
> under 127.0.0.1 i get prompted to download.
>
> How did you fix this?

It depends on your browser you are using.  By default Firefox will attempt to download JSON encoded data to a file while Safari and Chrome will just display it in the browser.

TJ


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

Jonathan Langevin
Thanks for that TJ, I had failed to mention that I only use Chrome browser.


Jonathan Langevin
Systems Administrator

Loom Inc.
Wilmington, NC: (910) 241-0433 - [hidden email] - www.loomlearning.com - Skype: intel352



On Thu, Aug 25, 2011 at 10:13 AM, TJ Ninneman <[hidden email]> wrote:
>
> Thanks alot... this seems to be the problem. When i navigate to JSON files
> under 127.0.0.1 i get prompted to download.
>
> How did you fix this?

It depends on your browser you are using.  By default Firefox will attempt to download JSON encoded data to a file while Safari and Chrome will just display it in the browser.

TJ


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
In reply to this post by TJ Ninneman
Well i don't really care if it opens in a browser properly or not. The python Riak client is returning this error so something is wrong. When I run it in the command line it returns a json object but im still getting that error.

Where do you set the application type header, are you talking about the bucket object, the object itself or is it something that is set on the riak server itself?
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

TJ Ninneman

> Well i don't really care if it opens in a browser properly or not. The python
> Riak client is returning this error so something is wrong. When I run it in
> the command line it returns a json object but im still getting that error.

I would play around with this using the python interpreter.  Instead of calling my_bucket.get(key), I would use my_bucket.get_binary(key).  This will give you the raw string stored in Riak instead of auto-decoding it.  Inspect the result; make sure it does indeed look like valid json.  If it does, I'd run it through the stdlib json.loads and see what happens.

> Where do you set the application type header, are you talking about the
> bucket object, the object itself or is it something that is set on the riak
> server itself?

It's an attribute of the object itself.  It's set by default to "application/json" as long as you are creating standard Riak objects and not Riak binaries.  See http://basho.github.com/riak-python-client/tutorial.html#storing-keys-values for more detail.

TJ
_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
when executing curl -v 127.0.0.1:8098/solr commands i get 404 errors. Im wondering if my Riak is not running search at all. I can riaksearch ping and it works but it i cannot access the solr interface.
Reply | Threaded
Open this post in threaded view
|

Re: Riak Problem w/ Python Client "No JSON object could be decoded"

idmartin
Does data have to be manually indexed?

Even if i don't have any data indexed shouldn't the python client return a different error if everything is working properly?