CouchApp 0.5.1 Error 400: {"error":"bad_request","reason":"invalid UTF-8 JSON"}

216 views
Skip to first unread message

Hilmer

unread,
Dec 9, 2009, 3:48:35 PM12/9/09
to CouchApp
Hi

I keep getting {"error":"bad_request","reason":"invalid UTF-8 JSON"}
after upgrading to couchapp 0.5.1.

The exact output is:
[INFO] push views/by_gcs_and_kreds/map.js
[CRITICAL] Error 400: {"error":"bad_request","reason":"invalid UTF-8
JSON"}

Traceback (most recent call last):
File "/usr/local/bin/couchapp", line 5, in <module>
pkg_resources.run_script('Couchapp==0.5.1', 'couchapp')
File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 489, in run_script

File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 1207, in run_script

File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/EGG-INFO/scripts/couchapp", line 28, in <module>
couchapp.dispatch.run()
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 29, in run
sys.exit(dispatch(sys.argv[1:]))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 40, in dispatch
return _dispatch(ui, args)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 85, in _dispatch
return fun(ui, path, *args, **opts)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/commands.py", line 68, in push
localdoc.push(dbs, opts.get('no_atomic', False))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/localdoc.py", line 114, in push
db.save_doc(doc)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbclient.py", line 372, in save_doc
res = self.res.put(docid, payload=doc, _raw_json=_raw_json,
**params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbresource.py", line 116, in put
return self.request('PUT', path=path, payload=payload,
headers=headers, **params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbresource.py", line 238, in request
raise RequestFailed("Error %s: %s" % (status_code, data))
couchapp.errors.RequestFailed: Error 400:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

and couchdb logs this:
[debug] [<0.4075.0>] 'PUT' /geocode/_design/geocode {1,1}
Headers: [{'Accept',"application/json"},
{'Accept-Encoding',"identity"},
{'Authorization',"Basic =removed="},
{'Content-Length',"516"},
{'Content-Type',"application/json"},
{'Host',"127.0.0.1:5984"},
{'User-Agent',"couchapp/0.5"}]
[debug] [<0.4075.0>] OAuth Params: []
[error] [<0.4075.0>] attempted upload of invalid JSON {"_attachments":
{}, "vendor": {"couchapp": {}}, "updates": {}, "couchapp":
{"manifest": ["vendor/", "vendor/couchapp/", "lists/", "updates/",
"shows/", "views/", "views/by_gcs_and_kreds/", "views/by_gcs_and_kreds/
map.js", "couchapp.json"], "signatures": {}, "name": "geocode",
"objects": {}, "description": "GeoCode"}, "views":
{"by_gcs_and_kreds": {"map": "function(doc){emit
([doc.gcs,doc.kreds],doc.placemark);}"}}, "_rev":
"2-138ec73647e007b96eb6c8b8c9e90844", "_id": "_design/geocode",
"lists": {},"shows": {}}
[info] [<0.4075.0>] 127.0.0.1 - - 'PUT' /geocode/_design/geocode 400
[debug] [<0.4075.0>] httpd 400 error response:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

I am running couchdb version: Apache CouchDB 0.11.0b888196

Can anybody shed some light over this?

--Søren

Benoit Chesneau

unread,
Dec 9, 2009, 6:44:53 PM12/9/09
to couc...@googlegroups.com
Can't reproduce here. Which os ?

- benoit

Hilmer

unread,
Dec 10, 2009, 3:58:05 AM12/10/09
to CouchApp
kubuntu Jaunty.

I tried outputting the payload inside the couchdbresource.py and
noticed a few odd 'u' characters like this:

"map": u"function(doc) ...
and
"_rev": u"2-138ec73647e007b96eb6c8b8c9e90844"

There is no weird characters in my map.js file, start of hexdump:
0x00000000: 66 75 6e 63 74 69 6f 6e - 28 64 6f 63 29 7b 65 6d function
(doc){em

--Søren

On Dec 10, 12:44 am, Benoit Chesneau <bchesn...@gmail.com> wrote:

Ryan Graham

unread,
Dec 10, 2009, 9:00:49 AM12/10/09
to couc...@googlegroups.com
Those 'u' prefixes just indicate that they are unicode strings. If
they weren't there, you might have even more problems.

What version did you upgrade from?

~Ryan

On Thu, Dec 10, 2009 at 12:58 AM, Hilmer <soren....@gmail.com> wrote:
>
> I tried outputting the payload inside the couchdbresource.py and
> noticed a few odd 'u' characters like this:
>
> "map": u"function(doc) ...
> and
> "_rev": u"2-138ec73647e007b96eb6c8b8c9e90844"

--
http://rmgraham.blogspot.com
http://twitter.com/rmgraham

Hilmer

unread,
Dec 10, 2009, 10:39:12 AM12/10/09
to CouchApp
Okay, I believe it was 0.4.
I have added the _id file, so that should be fine.

--Søren

On Dec 10, 3:00 pm, Ryan Graham <r.m.gra...@gmail.com> wrote:
> Those 'u' prefixes just indicate that they are unicode strings. If
> they weren't there, you might have even more problems.
>
> What version did you upgrade from?
>
> ~Ryan
>

Benoit Chesneau

unread,
Dec 10, 2009, 3:10:54 PM12/10/09
to couc...@googlegroups.com
On Thu, Dec 10, 2009 at 4:39 PM, Hilmer <soren....@gmail.com> wrote:
> Okay, I believe it was 0.4.
> I have added the _id file, so that should be fine.
>
> --Søren
>
not sure to follow, does it solve your problem ?

- benoit

Hilmer

unread,
Dec 10, 2009, 5:48:09 PM12/10/09
to CouchApp
No, it does not.

I just tried starting from scratch:
couchapp generate relax
couchapp push relax http://127.0.0.1:5984/relax
[INFO] database relax
created.
[CRITICAL] [Errno 2] No such file or directory: '/home/sh/dognrapport/
db/relax/relax'
py2.6.egg/couchapp/localdoc.py", line 108, in push
doc = self.doc()
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/localdoc.py", line 129, in doc
self._doc.update(self.dir_to_fields(self.docdir,
manifest=manifest))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/localdoc.py", line 207, in dir_to_fields
for name in os.listdir(current_dir):
OSError: [Errno 2] No such file or directory: '/home/sh/dognrapport/db/
relax/relax'
sh@euler:~/dognrapport/db/relax$ couchapp push http://admin:Couch42RSA.@127.0.0.1:5984/relax
[INFO] database relax created.
[CRITICAL] Error 400: {"error":"bad_request","reason":"invalid UTF-8
JSON"}

So it has nothing to do with my original map function.

--Søren

p.s. will try the new 0.5.2


On Dec 10, 9:10 pm, Benoit Chesneau <bchesn...@gmail.com> wrote:

Hilmer

unread,
Dec 10, 2009, 5:51:32 PM12/10/09
to CouchApp
Ahh my bad, wrong dump here is the right one:

couchapp push http://127.0.0.1:5984/relax
[INFO] database relax created.
[CRITICAL] Error 400: {"error":"bad_request","reason":"invalid UTF-8
JSON"}

Traceback (most recent call last):
File "/usr/local/bin/couchapp", line 5, in <module>
pkg_resources.run_script('Couchapp==0.5.1', 'couchapp')
File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 489, in run_script

File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 1207, in run_script

File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/EGG-INFO/scripts/couchapp", line 28, in <module>
couchapp.dispatch.run()
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 29, in run
sys.exit(dispatch(sys.argv[1:]))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 40, in dispatch
return _dispatch(ui, args)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/dispatch.py", line 85, in _dispatch
return fun(ui, path, *args, **opts)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/commands.py", line 68, in push
localdoc.push(dbs, opts.get('no_atomic', False))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/localdoc.py", line 114, in push
db.save_doc(doc)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbclient.py", line 372, in save_doc
res = self.res.put(docid, payload=doc, _raw_json=_raw_json,
**params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbresource.py", line 116, in put
return self.request('PUT', path=path, payload=payload,
headers=headers, **params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.1-
py2.6.egg/couchapp/couchdbresource.py", line 238, in request
raise RequestFailed("Error %s: %s" % (status_code, data))
couchapp.errors.RequestFailed: Error 400:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

--Søren

On Dec 10, 11:48 pm, Hilmer <soren.hil...@gmail.com> wrote:
> No, it does not.
>
> I just tried starting from scratch:
> couchapp generate relax
> couchapp  push relaxhttp://127.0.0.1:5984/relax
> sh@euler:~/dognrapport/db/relax$ couchapp  push http://admin:Couch42R...@127.0.0.1:5984/relax

Hilmer

unread,
Dec 10, 2009, 5:53:26 PM12/10/09
to CouchApp
Same behaviour with 0.5.2 (probably as expected, given the changes)

--Søren

On Dec 10, 11:51 pm, Hilmer <soren.hil...@gmail.com> wrote:
> Ahh my bad, wrong dump here is the right one:
>
> couchapp  pushhttp://127.0.0.1:5984/relax

Benoit Chesneau

unread,
Dec 10, 2009, 6:39:01 PM12/10/09
to CouchApp


On Dec 10, 11:53 pm, Hilmer <soren.hil...@gmail.com> wrote:
> Same behaviour with 0.5.2 (probably as expected, given the changes)
>
> --Søren
>

well the dump don't help. Could you push with verbose mode ? "-v".
Also if you can post your json it would help too. Thx for the feedback
anyway.

- benoit

Hilmer

unread,
Dec 11, 2009, 4:30:44 PM12/11/09
to CouchApp
Here is the output with -v option

[INFO] push vendor/couchapp/date.js
[INFO] push vendor/couchapp/metadata.json
[INFO] push vendor/couchapp/template.js
[INFO] push vendor/couchapp/path.js
[INFO] push vendor/couchapp/README.md
[INFO] push vendor/couchapp/couchapp.js
[INFO] attach index.html
[INFO] attach style/main.css
[INFO] attach vendor/couchapp/jquery.couchapp.js
[CRITICAL] Error 400: {"error":"bad_request","reason":"invalid UTF-8
JSON"}

Traceback (most recent call last):
File "/usr/local/bin/couchapp", line 5, in <module>
pkg_resources.run_script('Couchapp==0.5.2', 'couchapp')
File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 489, in run_script

File "/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-
py2.6.egg/pkg_resources.py", line 1207, in run_script

File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/EGG-INFO/scripts/couchapp", line 28, in <module>
couchapp.dispatch.run()
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/dispatch.py", line 29, in run
sys.exit(dispatch(sys.argv[1:]))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/dispatch.py", line 40, in dispatch
return _dispatch(ui, args)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/dispatch.py", line 85, in _dispatch
return fun(ui, path, *args, **opts)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/commands.py", line 75, in push
localdoc.push(dbs, opts.get('no_atomic', False))
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/localdoc.py", line 113, in push
db.save_doc(doc)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/couchdbclient.py", line 372, in save_doc
res = self.res.put(docid, payload=doc, _raw_json=_raw_json,
**params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/couchdbresource.py", line 116, in put
return self.request('PUT', path=path, payload=payload,
headers=headers, **params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/couchdbresource.py", line 238, in request
raise RequestFailed("Error %s: %s" % (status_code, data))
couchapp.errors.RequestFailed: Error 400:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

--Søren

Hilmer

unread,
Dec 12, 2009, 1:41:32 AM12/12/09
to CouchApp
I stripped down the relax to have nothing but what is in the main
directory.
I then added this: self.ui.logger.error("payload: %s" % payload)
to line 116 in couchdbresource.py
The output is below, as I said before i wonder about the 'u'
characters, I understand what Ryan said, but shouldn't they be all
over instead of just selected places?

--Søren

[ERROR] payload: {'_attachments': {}, 'vendor': {'couchapp': {}},
'updates': {}, 'couchapp': {'manifest': ['vendor/', 'vendor/
couchapp/', 'lists/', 'updates/', 'shows/', 'views/',
'couchapp.json'], 'signatures': {}, u'name': u'Name of your CouchApp',
'objects': {}, u'description': u'CouchApp'}, 'views': {}, '_id':
'_design/relax', 'lists': {}, 'shows': {}}
py2.6.egg/couchapp/couchdbresource.py", line 117, in put
return self.request('PUT', path=path, payload=payload,
headers=headers, **params)
File "/usr/local/lib/python2.6/dist-packages/Couchapp-0.5.2-
py2.6.egg/couchapp/couchdbresource.py", line 239, in request

Hilmer

unread,
Dec 12, 2009, 1:50:22 AM12/12/09
to CouchApp
Okay, I will get of your hair now, just tried making a document in
Futon and that fails with the same error, so it must be a CouchDB
thing.

Sorry about the noise.

--Søren

Benoit Chesneau

unread,
Dec 12, 2009, 2:14:56 AM12/12/09
to couc...@googlegroups.com
On Sat, Dec 12, 2009 at 7:50 AM, Hilmer <soren....@gmail.com> wrote:
> Okay, I will get of your hair now, just tried making a document in
> Futon and that fails with the same error, so it must be a CouchDB
> thing.
>
> Sorry about the noise.
>
> --Søren
>

np. Check you don't have any character in your contents that isn't
utf8. If you can send me the content I could also on my side, couchapp
should handle conversion (and make it in most case) so I'm curious :)

- benoit

Hilmer

unread,
Dec 13, 2009, 2:31:39 PM12/13/09
to CouchApp
Well at the end I had no content of my own, I just pushed what was
generated by couchapp generate.
It was some conflict resulting from couchdb not having cleaned up
enough when issuing 'make uninstall' prior to 'make install'

I had forgot that I upgraded couchdb the day before couchapp, so I
started blaming couchapp, which turned out to be wrong, sorry.

--Søren

On Dec 12, 8:14 am, Benoit Chesneau <bchesn...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages