Encoding problem - or bug in couchdb-0.8-py2.7.egg??
Ian
hobson42 at gmaiil.com
Mon Sep 20 13:30:22 EDT 2010
Thanks Diez,
Removing, rebooting and installing the latest version solved the
problem. :)
Your google-foo is better than mine. Google had not turned that up for me.
Thanks again
Regards
Ian
On 20/09/2010 17:00, Diez B. Roggisch wrote:
> Ian Hobson<ian at ianhobson.co.uk> writes:
>
>> Hi all,
>>
>> I have hit a problem and I don't know enough about python to diagnose
>> things further. Trying to use couchDB from Python. This script:-
>>
>> # coding=utf8
>> import couchdb
>> from couchdb.client import Server
>> server = Server()
>> dbName = 'python-tests'
>> try:
>> db = server.create(dbName)
>> except couchdb.PreconditionFailed:
>> del server[dbName]
>> db = server.create(dbName)
>> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'})
>>
>> Gives this traceback:-
>>
>> D:\work\C-U-B>python tes1.py
>> Traceback (most recent call last):
>> File "tes1.py", line 11, in<module>
>> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'})
>> File
>> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py",
>> line 407, in save
>> _, _, data = func(body=doc, **options)
>> File
>> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py",
>> line 399, in post_json
>> status, headers, data = self.post(*a, **k)
>> File
>> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py",
>> line 381, in post
>> **params)
>> File
>> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py",
>> line 419, in _request
>> credentials=self.credentials)
>> File
>> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py",
>> line 310, in request
>> raise ServerError((status, error))
>> couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON'))
>>
>> D:\work\C-U-B>
>>
>> Why? I've tried adding u to the strings, and removing the # coding
>> line, and I still get the same error.
> Sounds cargo-cultish. I suggest you read the python introduction on
> unicode.
>
> http://docs.python.org/howto/unicode.html
>
> For your actual problem, I have difficulties seeing how it can happen
> with the above data - frankly because there is nothing outside the
> ascii-range of data, so there is no reason why anything could be wrong
> encoded.
I came to the same conclusion.
> But googling the error-message reveals that there seem to be totally
> unrelated reasons for this:
>
> http://sindro.me/2010/4/3/couchdb-invalid-utf8-json
>
> Maybe using something like tcpmon or ethereal to capture the actual
> HTTP-request helps to see where the issue comes from.
>
> Diez
More information about the Python-list
mailing list