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

Discussion in 'Python' started by Ian Hobson, Sep 20, 2010.

  1. Ian Hobson

    Ian Hobson Guest

    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
    Ian Hobson, Sep 20, 2010
    #1
    1. Advertising

  2. Ian Hobson <> 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
    Diez B. Roggisch, Sep 20, 2010
    #2
    1. Advertising

  3. Ian Hobson

    Ian Guest

    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<> 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
    Ian, Sep 20, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Holger Joukl

    py2.1->py2.3.3 __getattr__ confusion

    Holger Joukl, Jul 2, 2004, in forum: Python
    Replies:
    1
    Views:
    307
    Peter Otten
    Jul 2, 2004
  2. Holger Joukl
    Replies:
    2
    Views:
    253
    Michael Hudson
    Jul 9, 2004
  3. Josef Dalcolmo

    getmtime differs between Py2.5 and Py2.4

    Josef Dalcolmo, May 7, 2007, in forum: Python
    Replies:
    16
    Views:
    535
    Joe Salmeri
    Jun 1, 2007
  4. Catherine
    Replies:
    2
    Views:
    317
    John Nagle
    Oct 8, 2007
  5. R. Bernstein
    Replies:
    3
    Views:
    364
    R. Bernstein
    Dec 21, 2008
Loading...

Share This Page