Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Encoding problem - or bug in couchdb-0.8-py2.7.egg??

Reply
Thread Tools

Encoding problem - or bug in couchdb-0.8-py2.7.egg??

 
 
Ian Hobson
Guest
Posts: n/a
 
      09-20-2010
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.

Thanks for any help.

Ian


 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      09-20-2010
Ian Hobson <(E-Mail Removed)> 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.

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
 
Reply With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      09-20-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<(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
javac -encoding problem and/or glaring bug ? java Java 6 08-19-2007 11:22 AM
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
changing JVM encoding; setting -Dfile.encoding doesn't work pasmol@plusnet.pl Java 1 10-08-2004 09:50 PM
Encoding.Default and Encoding.UTF8 Hardy Wang ASP .Net 5 06-09-2004 04:04 PM



Advertisments