You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Florian Leitner <fl...@gmail.com> on 2010/11/25 19:32:31 UTC

curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Hi there,

I've got a peculiar problem. I installed the latest CouchDBX.app for
OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
and all worked nicely. However, now I am trying to POST to the
_temp_view of my "hello-world" database, and I get the "invalid UTF-8
JSON" error without knowing what I am doing wrong - curl worked nicely
for all other commands and if I run the view from Futon, it works
nicely, too. Here is what happens with curl (I have three documents in
"hello-world"):

$ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
emit(null, doc) }"'
* About to connect() to 127.0.0.1 port 5984 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> POST /hello-world/_temp_view HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: 127.0.0.1:5984
> Accept: */*
> Content-Type: application/json;charset=utf-8
> Content-Length: 43
>
< HTTP/1.1 400 Bad Request
< Server: CouchDB/1.0.1 (Erlang OTP/R13B)
< Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
* Closing connection #0

Here is the request against the database (with some spaces between
key/value pairs to make it readable):

$ curl-json $DB
{"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
"update_seq":16, "purge_seq":0, "compact_running":false,
"disk_size":61529, "instance_start_time":"1290702185923299",
"disk_format_version":5, "committed_update_seq":16}

Last but not least, I've aliased curl-json as such:

alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'

I've also tried to leave out the charset part, naturally, to no avail.
DB is set to (as guessed):

DB=http://127.0.0.1:5984/hello-world

So can someone tell me why I am getting this UTF-8 issue? I could POST
documents without problems, put now POSTing to _temp_view seems to
fail. Any help appreciated.

Thanks,
Florian

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Jan Lehnardt <ja...@apache.org>.
On 26 Nov 2010, at 11:50, Florian Leitner wrote:

> How embarrassing... Well, thanks lots for the hint!

We all make mistakes :) — Hope things work fine for you now!

Cheers
Jan
-- 

> 
> -- Florian
> 
> On 26 November 2010 10:23, JC de Villa <jc...@gmail.com> wrote:
>> You're missing a closing curly bracket before that last single quote.
>> 
>> JC de Villa
>> 
>> 
>> On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
>> <fl...@gmail.com>wrote:
>> 
>>> Hi there,
>>> 
>>> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
>>> installed the latest CouchDBX.app for
>>> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
>>> and all worked nicely so far. However, now I am trying to POST to the
>>> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
>>> JSON" error without knowing what I am doing wrong - curl worked nicely
>>> for all other commands and if I run the view from Futon, it works
>>> nicely, too. Here is what happens with curl (I have three documents in
>>> "hello-world"):
>>> 
>>> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
>>> emit(null, doc) }"'
>>> * About to connect() to 127.0.0.1 port 5984 (#0)
>>> *   Trying 127.0.0.1... connected
>>> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
>>>> POST /hello-world/_temp_view HTTP/1.1
>>>> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
>>> OpenSSL/0.9.8l zlib/1.2.3
>>>> Host: 127.0.0.1:5984
>>>> Accept: */*
>>>> Content-Type: application/json;charset=utf-8
>>>> Content-Length: 43
>>>> 
>>> < HTTP/1.1 400 Bad Request
>>> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
>>> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
>>> * Closing connection #0
>>> 
>>> Here is the request against the database (with some spaces between
>>> key/value pairs to make it readable):
>>> 
>>> $ curl-json $DB
>>> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
>>> "update_seq":16, "purge_seq":0, "compact_running":false,
>>> "disk_size":61529, "instance_start_time":"1290702185923299",
>>> "disk_format_version":5, "committed_update_seq":16}
>>> 
>>> Last but not least, I've aliased curl-json as such:
>>> 
>>> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>>> 
>>> I've also tried to leave out the charset part, naturally, to no avail.
>>> DB is set to (as guessed):
>>> 
>>> DB=http://127.0.0.1:5984/hello-world
>>> 
>>> So can someone tell me why I am getting this UTF-8 issue? I could POST
>>> documents without encoding problems, put now POSTing to _temp_view seems to
>>> fail. Any help appreciated.
>>> 
>>> Thanks,
>>> Florian
>>> 
>> 


Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by JC de Villa <jc...@gmail.com>.
You're very welcome. And don't worry. I've spent more than a few hours
figuring that out when I started. :-)
JC de Villa


On Fri, Nov 26, 2010 at 6:50 PM, Florian Leitner
<fl...@gmail.com>wrote:

> How embarrassing... Well, thanks lots for the hint!
>
> -- Florian
>
> On 26 November 2010 10:23, JC de Villa <jc...@gmail.com> wrote:
> > You're missing a closing curly bracket before that last single quote.
> >
> > JC de Villa
> >
> >
> > On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
> > <fl...@gmail.com>wrote:
> >
> >> Hi there,
> >>
> >> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
> >> installed the latest CouchDBX.app for
> >> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
> >> and all worked nicely so far. However, now I am trying to POST to the
> >> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
> >> JSON" error without knowing what I am doing wrong - curl worked nicely
> >> for all other commands and if I run the view from Futon, it works
> >> nicely, too. Here is what happens with curl (I have three documents in
> >> "hello-world"):
> >>
> >> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
> >> emit(null, doc) }"'
> >> * About to connect() to 127.0.0.1 port 5984 (#0)
> >> *   Trying 127.0.0.1... connected
> >> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> >> > POST /hello-world/_temp_view HTTP/1.1
> >> > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
> >> OpenSSL/0.9.8l zlib/1.2.3
> >> > Host: 127.0.0.1:5984
> >> > Accept: */*
> >> > Content-Type: application/json;charset=utf-8
> >> > Content-Length: 43
> >> >
> >> < HTTP/1.1 400 Bad Request
> >> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
> >> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
> >> * Closing connection #0
> >>
> >> Here is the request against the database (with some spaces between
> >> key/value pairs to make it readable):
> >>
> >> $ curl-json $DB
> >> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
> >> "update_seq":16, "purge_seq":0, "compact_running":false,
> >> "disk_size":61529, "instance_start_time":"1290702185923299",
> >> "disk_format_version":5, "committed_update_seq":16}
> >>
> >> Last but not least, I've aliased curl-json as such:
> >>
> >> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
> >>
> >> I've also tried to leave out the charset part, naturally, to no avail.
> >> DB is set to (as guessed):
> >>
> >> DB=http://127.0.0.1:5984/hello-world
> >>
> >> So can someone tell me why I am getting this UTF-8 issue? I could POST
> >> documents without encoding problems, put now POSTing to _temp_view seems
> to
> >> fail. Any help appreciated.
> >>
> >> Thanks,
> >> Florian
> >>
> >
>

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Florian Leitner <fl...@gmail.com>.
Great tip, thanks, Mark!

--Florian

On 26 November 2010 15:22, Mark J. Reed <ma...@gmail.com> wrote:
> When hand-constructing or -editing JSON, it's a good idea to run it
> through a parser to make sure it's valid. Modern python installs come
> with a module for that.  Just save the JSON in a file and run
>
> python -mjson.tool <filename
>
> It will either spit out an error message or else pretty-print the
> JSON, in which case you know it's valid. Then you can use the
> -d@filename option to feed the file directly to curl.
>
> On Friday, November 26, 2010, Florian Leitner <fl...@gmail.com> wrote:
>> How embarrassing... Well, thanks lots for the hint!
>>
>> -- Florian
>>
>> On 26 November 2010 10:23, JC de Villa <jc...@gmail.com> wrote:
>>> You're missing a closing curly bracket before that last single quote.
>>>
>>> JC de Villa
>>>
>>>
>>> On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
>>> <fl...@gmail.com>wrote:
>>>
>>>> Hi there,
>>>>
>>>> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
>>>> installed the latest CouchDBX.app for
>>>> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
>>>> and all worked nicely so far. However, now I am trying to POST to the
>>>> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
>>>> JSON" error without knowing what I am doing wrong - curl worked nicely
>>>> for all other commands and if I run the view from Futon, it works
>>>> nicely, too. Here is what happens with curl (I have three documents in
>>>> "hello-world"):
>>>>
>>>> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
>>>> emit(null, doc) }"'
>>>> * About to connect() to 127.0.0.1 port 5984 (#0)
>>>> *   Trying 127.0.0.1... connected
>>>> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
>>>> > POST /hello-world/_temp_view HTTP/1.1
>>>> > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
>>>> OpenSSL/0.9.8l zlib/1.2.3
>>>> > Host: 127.0.0.1:5984
>>>> > Accept: */*
>>>> > Content-Type: application/json;charset=utf-8
>>>> > Content-Length: 43
>>>> >
>>>> < HTTP/1.1 400 Bad Request
>>>> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
>>>> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
>>>> * Closing connection #0
>>>>
>>>> Here is the request against the database (with some spaces between
>>>> key/value pairs to make it readable):
>>>>
>>>> $ curl-json $DB
>>>> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
>>>> "update_seq":16, "purge_seq":0, "compact_running":false,
>>>> "disk_size":61529, "instance_start_time":"1290702185923299",
>>>> "disk_format_version":5, "committed_update_seq":16}
>>>>
>>>> Last but not least, I've aliased curl-json as such:
>>>>
>>>> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>>>>
>>>> I've also tried to leave out the charset part, naturally, to no avail.
>>>> DB is set to (as guessed):
>>>>
>>>> DB=http://127.0.0.1:5984/hello-world
>>>>
>>>> So can someone tell me why I am getting this UTF-8 issue? I could POST
>>>> documents without encoding problems, put now POSTing to _temp_view seems to
>>>> fail. Any help appreciated.
>>>>
>>>> Thanks,
>>>> Florian
>>>>
>>>
>>
>
> --
> Mark J. Reed <ma...@gmail.com>
>

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Nils Breunese <N....@vpro.nl>.
Mark J. Reed wrote:

> When hand-constructing or -editing JSON, it's a good idea to run it
> through a parser to make sure it's valid. Modern python installs come
> with a module for that.  Just save the JSON in a file and run
>
> python -mjson.tool <filename
>
> It will either spit out an error message or else pretty-print the
> JSON, in which case you know it's valid.

You can also use http://jsonlint.com/ for the same purpose.

Nils.
------------------------------------------------------------------------
 VPRO
 phone:  +31(0)356712911
 e-mail: info@vpro.nl
 web:    www.vpro.nl
------------------------------------------------------------------------

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by "Mark J. Reed" <ma...@gmail.com>.
When hand-constructing or -editing JSON, it's a good idea to run it
through a parser to make sure it's valid. Modern python installs come
with a module for that.  Just save the JSON in a file and run

python -mjson.tool <filename

It will either spit out an error message or else pretty-print the
JSON, in which case you know it's valid. Then you can use the
-d@filename option to feed the file directly to curl.

On Friday, November 26, 2010, Florian Leitner <fl...@gmail.com> wrote:
> How embarrassing... Well, thanks lots for the hint!
>
> -- Florian
>
> On 26 November 2010 10:23, JC de Villa <jc...@gmail.com> wrote:
>> You're missing a closing curly bracket before that last single quote.
>>
>> JC de Villa
>>
>>
>> On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
>> <fl...@gmail.com>wrote:
>>
>>> Hi there,
>>>
>>> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
>>> installed the latest CouchDBX.app for
>>> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
>>> and all worked nicely so far. However, now I am trying to POST to the
>>> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
>>> JSON" error without knowing what I am doing wrong - curl worked nicely
>>> for all other commands and if I run the view from Futon, it works
>>> nicely, too. Here is what happens with curl (I have three documents in
>>> "hello-world"):
>>>
>>> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
>>> emit(null, doc) }"'
>>> * About to connect() to 127.0.0.1 port 5984 (#0)
>>> *   Trying 127.0.0.1... connected
>>> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
>>> > POST /hello-world/_temp_view HTTP/1.1
>>> > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
>>> OpenSSL/0.9.8l zlib/1.2.3
>>> > Host: 127.0.0.1:5984
>>> > Accept: */*
>>> > Content-Type: application/json;charset=utf-8
>>> > Content-Length: 43
>>> >
>>> < HTTP/1.1 400 Bad Request
>>> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
>>> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
>>> * Closing connection #0
>>>
>>> Here is the request against the database (with some spaces between
>>> key/value pairs to make it readable):
>>>
>>> $ curl-json $DB
>>> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
>>> "update_seq":16, "purge_seq":0, "compact_running":false,
>>> "disk_size":61529, "instance_start_time":"1290702185923299",
>>> "disk_format_version":5, "committed_update_seq":16}
>>>
>>> Last but not least, I've aliased curl-json as such:
>>>
>>> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>>>
>>> I've also tried to leave out the charset part, naturally, to no avail.
>>> DB is set to (as guessed):
>>>
>>> DB=http://127.0.0.1:5984/hello-world
>>>
>>> So can someone tell me why I am getting this UTF-8 issue? I could POST
>>> documents without encoding problems, put now POSTing to _temp_view seems to
>>> fail. Any help appreciated.
>>>
>>> Thanks,
>>> Florian
>>>
>>
>

-- 
Mark J. Reed <ma...@gmail.com>

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Florian Leitner <fl...@gmail.com>.
How embarrassing... Well, thanks lots for the hint!

-- Florian

On 26 November 2010 10:23, JC de Villa <jc...@gmail.com> wrote:
> You're missing a closing curly bracket before that last single quote.
>
> JC de Villa
>
>
> On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
> <fl...@gmail.com>wrote:
>
>> Hi there,
>>
>> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
>> installed the latest CouchDBX.app for
>> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
>> and all worked nicely so far. However, now I am trying to POST to the
>> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
>> JSON" error without knowing what I am doing wrong - curl worked nicely
>> for all other commands and if I run the view from Futon, it works
>> nicely, too. Here is what happens with curl (I have three documents in
>> "hello-world"):
>>
>> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
>> emit(null, doc) }"'
>> * About to connect() to 127.0.0.1 port 5984 (#0)
>> *   Trying 127.0.0.1... connected
>> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
>> > POST /hello-world/_temp_view HTTP/1.1
>> > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
>> OpenSSL/0.9.8l zlib/1.2.3
>> > Host: 127.0.0.1:5984
>> > Accept: */*
>> > Content-Type: application/json;charset=utf-8
>> > Content-Length: 43
>> >
>> < HTTP/1.1 400 Bad Request
>> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
>> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
>> * Closing connection #0
>>
>> Here is the request against the database (with some spaces between
>> key/value pairs to make it readable):
>>
>> $ curl-json $DB
>> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
>> "update_seq":16, "purge_seq":0, "compact_running":false,
>> "disk_size":61529, "instance_start_time":"1290702185923299",
>> "disk_format_version":5, "committed_update_seq":16}
>>
>> Last but not least, I've aliased curl-json as such:
>>
>> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>>
>> I've also tried to leave out the charset part, naturally, to no avail.
>> DB is set to (as guessed):
>>
>> DB=http://127.0.0.1:5984/hello-world
>>
>> So can someone tell me why I am getting this UTF-8 issue? I could POST
>> documents without encoding problems, put now POSTing to _temp_view seems to
>> fail. Any help appreciated.
>>
>> Thanks,
>> Florian
>>
>

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by JC de Villa <jc...@gmail.com>.
You're missing a closing curly bracket before that last single quote.

JC de Villa


On Fri, Nov 26, 2010 at 2:36 AM, Florian Leitner
<fl...@gmail.com>wrote:

> Hi there,
>
> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
> installed the latest CouchDBX.app for
> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
> and all worked nicely so far. However, now I am trying to POST to the
> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
> JSON" error without knowing what I am doing wrong - curl worked nicely
> for all other commands and if I run the view from Futon, it works
> nicely, too. Here is what happens with curl (I have three documents in
> "hello-world"):
>
> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
> emit(null, doc) }"'
> * About to connect() to 127.0.0.1 port 5984 (#0)
> *   Trying 127.0.0.1... connected
> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> > POST /hello-world/_temp_view HTTP/1.1
> > User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7
> OpenSSL/0.9.8l zlib/1.2.3
> > Host: 127.0.0.1:5984
> > Accept: */*
> > Content-Type: application/json;charset=utf-8
> > Content-Length: 43
> >
> < HTTP/1.1 400 Bad Request
> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
> * Closing connection #0
>
> Here is the request against the database (with some spaces between
> key/value pairs to make it readable):
>
> $ curl-json $DB
> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
> "update_seq":16, "purge_seq":0, "compact_running":false,
> "disk_size":61529, "instance_start_time":"1290702185923299",
> "disk_format_version":5, "committed_update_seq":16}
>
> Last but not least, I've aliased curl-json as such:
>
> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>
> I've also tried to leave out the charset part, naturally, to no avail.
> DB is set to (as guessed):
>
> DB=http://127.0.0.1:5984/hello-world
>
> So can someone tell me why I am getting this UTF-8 issue? I could POST
> documents without encoding problems, put now POSTing to _temp_view seems to
> fail. Any help appreciated.
>
> Thanks,
> Florian
>

Re: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Robert Newson <ro...@gmail.com>.
Because this;

{"map": "function(doc) {emit(null, doc) }"

is not valid JSON. Try this;

{"map": "function(doc) {emit(null, doc) }"}

B.

On Thu, Nov 25, 2010 at 6:36 PM, Florian Leitner
<fl...@gmail.com> wrote:
> Hi there,
>
> I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
> installed the latest CouchDBX.app for
> OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
> and all worked nicely so far. However, now I am trying to POST to the
> _temp_view of my "hello-world" database, and I get the "invalid UTF-8
> JSON" error without knowing what I am doing wrong - curl worked nicely
> for all other commands and if I run the view from Futon, it works
> nicely, too. Here is what happens with curl (I have three documents in
> "hello-world"):
>
> $ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
> emit(null, doc) }"'
> * About to connect() to 127.0.0.1 port 5984 (#0)
> *   Trying 127.0.0.1... connected
> * Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
>> POST /hello-world/_temp_view HTTP/1.1
>> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
>> Host: 127.0.0.1:5984
>> Accept: */*
>> Content-Type: application/json;charset=utf-8
>> Content-Length: 43
>>
> < HTTP/1.1 400 Bad Request
> < Server: CouchDB/1.0.1 (Erlang OTP/R13B)
> < Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
> * Closing connection #0
>
> Here is the request against the database (with some spaces between
> key/value pairs to make it readable):
>
> $ curl-json $DB
> {"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
> "update_seq":16, "purge_seq":0, "compact_running":false,
> "disk_size":61529, "instance_start_time":"1290702185923299",
> "disk_format_version":5, "committed_update_seq":16}
>
> Last but not least, I've aliased curl-json as such:
>
> alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'
>
> I've also tried to leave out the charset part, naturally, to no avail.
> DB is set to (as guessed):
>
> DB=http://127.0.0.1:5984/hello-world
>
> So can someone tell me why I am getting this UTF-8 issue? I could POST
> documents without encoding problems, put now POSTing to _temp_view seems to
> fail. Any help appreciated.
>
> Thanks,
> Florian
>

Fwd: curl POST to couchdb's _temp_view on OSX => invalid UTF-8

Posted by Florian Leitner <fl...@gmail.com>.
Hi there,

I've got a peculiar problem with the UTF-8 encoding in CouchDB. I
installed the latest CouchDBX.app for
OSX (CouchDB version 1.0.1, curl version 7.19.7, OSX version 10.6.4)
and all worked nicely so far. However, now I am trying to POST to the
_temp_view of my "hello-world" database, and I get the "invalid UTF-8
JSON" error without knowing what I am doing wrong - curl worked nicely
for all other commands and if I run the view from Futon, it works
nicely, too. Here is what happens with curl (I have three documents in
"hello-world"):

$ curl-json -vX POST "$DB/_temp_view" -d '{"map": "function(doc) {
emit(null, doc) }"'
* About to connect() to 127.0.0.1 port 5984 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> POST /hello-world/_temp_view HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: 127.0.0.1:5984
> Accept: */*
> Content-Type: application/json;charset=utf-8
> Content-Length: 43
>
< HTTP/1.1 400 Bad Request
< Server: CouchDB/1.0.1 (Erlang OTP/R13B)
< Date: Thu, 25 Nov 2010 18:19:07 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 127.0.0.1 left intact
* Closing connection #0

Here is the request against the database (with some spaces between
key/value pairs to make it readable):

$ curl-json $DB
{"db_name":"hello-world", "doc_count":3, "doc_del_count":6,
"update_seq":16, "purge_seq":0, "compact_running":false,
"disk_size":61529, "instance_start_time":"1290702185923299",
"disk_format_version":5, "committed_update_seq":16}

Last but not least, I've aliased curl-json as such:

alias curl-json='curl -H"Content-Type: application/json;charset=utf-8"'

I've also tried to leave out the charset part, naturally, to no avail.
DB is set to (as guessed):

DB=http://127.0.0.1:5984/hello-world

So can someone tell me why I am getting this UTF-8 issue? I could POST
documents without encoding problems, put now POSTing to _temp_view seems to
fail. Any help appreciated.

Thanks,
Florian