You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by erich oliphant <er...@gmail.com> on 2010/03/17 01:33:01 UTC

"invalid UTF-8 JSON" 400 error accessing view with 'key' parameter

Hi,
I am a new CouchDB user.  I've populated my db with some documents and I've
begun delving into views.  I have a simple view that seems to work fine with
no params, like so:

curl -X GET http://localhost:5984/testerp1/_design/onestop/_view/PONumbers
{"total_rows":104,"offset":0,"rows":[
{"id":"d15d7d12-af01-4137-b56e-2bb2fdea5721","key":"AAA-99036","value":"d15d7d12-af01-4137-b56e-2bb2fdea5721"},
{"id":"3e1d30ba-759f-4bff-b6c7-64536d772b09","key":"AAA-99057","value":"3e1d30ba-759f-4bff-b6c7-64536d772b09"},
...
However trying to grab a single result, causes a 400
curl -vX GET
http://localhost:5984/testerp1/_design/onestop/_view/PONumbers?key=
"AAA-99057"
* About to connect() to localhost port 5984 (#0)
*   Trying ::1... Connection refused
*   Trying fe80::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
> GET /testerp1/_design/onestop/_view/PONumbers?key=AAA-99057 HTTP/1.1
> User-Agent: curl/7.20.0 (i386-apple-darwin10.2.0) libcurl/7.20.0
OpenSSL/0.9.8m zlib/1.2.4 libidn/1.16
> Host: localhost:5984
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Server: CouchDB/0.10.1 (Erlang OTP/R13B)
< Date: Wed, 17 Mar 2010 00:28:46 GMT
< Content-Type: text/plain;charset=utf-8
< Content-Length: 54
< Cache-Control: must-revalidate
<
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
* Connection #0 to host localhost left intact
* Closing connection #0

I've tried the key param with and without quotes,etc but get the same
issue.   All of the other issues I've seen online have been related to PUT
bodies not being encoded correctly, but I've seen nothing similar to my
case.

Thanks In Advance
-- 
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Re: "invalid UTF-8 JSON" 400 error accessing view with 'key' parameter

Posted by erich oliphant <er...@gmail.com>.
Thanks for the additional info.   I actually ran into the quote problem
using a java client (RESTEasy) and had to use the %22



On Wed, Mar 17, 2010 at 5:08 AM, Brian Candler <B....@pobox.com> wrote:

> On Tue, Mar 16, 2010 at 08:49:01PM -0400, erich oliphant wrote:
> > Thanks worked like a charm!
>
> And for future reference, certain characters must be escaped in URIs into
> percent hex form. These are (see RFC 3986)
>
>      gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
>
>      sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
>                  / "*" / "+" / "," / ";" / "="
>
> You should also encode space (%20), as most HTTP implementations require
> this, including couchdb.
>
> It's optional whether you encode double quotes to %22, but that would be an
> alternative way of solving your shell quoting problem.
>
> Regards,
>
> Brian.
>



-- 
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Re: "invalid UTF-8 JSON" 400 error accessing view with 'key' parameter

Posted by Brian Candler <B....@pobox.com>.
On Tue, Mar 16, 2010 at 08:49:01PM -0400, erich oliphant wrote:
> Thanks worked like a charm!

And for future reference, certain characters must be escaped in URIs into
percent hex form. These are (see RFC 3986)

      gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"

      sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

You should also encode space (%20), as most HTTP implementations require
this, including couchdb.

It's optional whether you encode double quotes to %22, but that would be an
alternative way of solving your shell quoting problem.

Regards,

Brian.

Re: "invalid UTF-8 JSON" 400 error accessing view with 'key' parameter

Posted by erich oliphant <er...@gmail.com>.
Thanks worked like a charm!

On Tue, Mar 16, 2010 at 8:45 PM, Jan Lehnardt <ja...@apache.org> wrote:

> Hi Erich,
>
> On 16 Mar 2010, at 19:33, erich oliphant wrote:
>
> > I am a new CouchDB user.
>
> Welcome :)
>
> > I've populated my db with some documents and I've
> > begun delving into views.  I have a simple view that seems to work fine
> with
> > no params, like so:
> >
> > curl -X GET
> http://localhost:5984/testerp1/_design/onestop/_view/PONumbers
> > {"total_rows":104,"offset":0,"rows":[
> >
> {"id":"d15d7d12-af01-4137-b56e-2bb2fdea5721","key":"AAA-99036","value":"d15d7d12-af01-4137-b56e-2bb2fdea5721"},
> >
> {"id":"3e1d30ba-759f-4bff-b6c7-64536d772b09","key":"AAA-99057","value":"3e1d30ba-759f-4bff-b6c7-64536d772b09"},
> > ...
> > However trying to grab a single result, causes a 400
> > curl -vX GET
> > http://localhost:5984/testerp1/_design/onestop/_view/PONumbers?key=
> > "AAA-99057"
>
> Your shell interprets the double quotes. Try this:
>
>  curl -vX GET '
> http://localhost:5984/testerp1/_design/onestop/_view/PONumbers?key=
> "AAA-99057"'
>
> Cheers
> Jan
> --
>
>
>
> > * About to connect() to localhost port 5984 (#0)
> > *   Trying ::1... Connection refused
> > *   Trying fe80::1... Connection refused
> > *   Trying 127.0.0.1... connected
> > * Connected to localhost (127.0.0.1) port 5984 (#0)
> >> GET /testerp1/_design/onestop/_view/PONumbers?key=AAA-99057 HTTP/1.1
> >> User-Agent: curl/7.20.0 (i386-apple-darwin10.2.0) libcurl/7.20.0
> > OpenSSL/0.9.8m zlib/1.2.4 libidn/1.16
> >> Host: localhost:5984
> >> Accept: */*
> >>
> > < HTTP/1.1 400 Bad Request
> > < Server: CouchDB/0.10.1 (Erlang OTP/R13B)
> > < Date: Wed, 17 Mar 2010 00:28:46 GMT
> > < Content-Type: text/plain;charset=utf-8
> > < Content-Length: 54
> > < Cache-Control: must-revalidate
> > <
> > {"error":"bad_request","reason":"invalid UTF-8 JSON"}
> > * Connection #0 to host localhost left intact
> > * Closing connection #0
> >
> > I've tried the key param with and without quotes,etc but get the same
> > issue.   All of the other issues I've seen online have been related to
> PUT
> > bodies not being encoded correctly, but I've seen nothing similar to my
> > case.
> >
> > Thanks In Advance
> > --
> > Erich Oliphant
> >
> > "There are, in fact, two things, science and opinion, the former begets
> > knowledge, the latter ignorance"
> > -- Hippocrates of Cos
>
>


-- 
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Re: "invalid UTF-8 JSON" 400 error accessing view with 'key' parameter

Posted by Jan Lehnardt <ja...@apache.org>.
Hi Erich,

On 16 Mar 2010, at 19:33, erich oliphant wrote:

> I am a new CouchDB user.  

Welcome :)

> I've populated my db with some documents and I've
> begun delving into views.  I have a simple view that seems to work fine with
> no params, like so:
> 
> curl -X GET http://localhost:5984/testerp1/_design/onestop/_view/PONumbers
> {"total_rows":104,"offset":0,"rows":[
> {"id":"d15d7d12-af01-4137-b56e-2bb2fdea5721","key":"AAA-99036","value":"d15d7d12-af01-4137-b56e-2bb2fdea5721"},
> {"id":"3e1d30ba-759f-4bff-b6c7-64536d772b09","key":"AAA-99057","value":"3e1d30ba-759f-4bff-b6c7-64536d772b09"},
> ...
> However trying to grab a single result, causes a 400
> curl -vX GET
> http://localhost:5984/testerp1/_design/onestop/_view/PONumbers?key=
> "AAA-99057"

Your shell interprets the double quotes. Try this:

  curl -vX GET 'http://localhost:5984/testerp1/_design/onestop/_view/PONumbers?key="AAA-99057"'

Cheers
Jan
--



> * About to connect() to localhost port 5984 (#0)
> *   Trying ::1... Connection refused
> *   Trying fe80::1... Connection refused
> *   Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 5984 (#0)
>> GET /testerp1/_design/onestop/_view/PONumbers?key=AAA-99057 HTTP/1.1
>> User-Agent: curl/7.20.0 (i386-apple-darwin10.2.0) libcurl/7.20.0
> OpenSSL/0.9.8m zlib/1.2.4 libidn/1.16
>> Host: localhost:5984
>> Accept: */*
>> 
> < HTTP/1.1 400 Bad Request
> < Server: CouchDB/0.10.1 (Erlang OTP/R13B)
> < Date: Wed, 17 Mar 2010 00:28:46 GMT
> < Content-Type: text/plain;charset=utf-8
> < Content-Length: 54
> < Cache-Control: must-revalidate
> <
> {"error":"bad_request","reason":"invalid UTF-8 JSON"}
> * Connection #0 to host localhost left intact
> * Closing connection #0
> 
> I've tried the key param with and without quotes,etc but get the same
> issue.   All of the other issues I've seen online have been related to PUT
> bodies not being encoded correctly, but I've seen nothing similar to my
> case.
> 
> Thanks In Advance
> -- 
> Erich Oliphant
> 
> "There are, in fact, two things, science and opinion, the former begets
> knowledge, the latter ignorance"
> -- Hippocrates of Cos