Issue 235 in couchdb-python: Doc write exception with unicode characters

7 views
Skip to first unread message

couchdb...@googlecode.com

unread,
Apr 28, 2014, 5:42:41 PM4/28/14
to couchdb...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 235 by hhmw56...@gmail.com: Doc write exception with unicode
characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

What steps will reproduce the problem?

The following test script fails with 0.9, but works fine with 0.8:

import json
import couchdb

db = couchdb.Server(u"https://<username>:<password>@<server>")['<database>']
docs = [{u'Type':"TestDoc", u'Test':True, u'val':unichr(40960)}]
ret = db.update( docs )
print ret


What is the expected output? What do you see instead?

The write should succeed.

The exception is:

File "couch_encoding_test.py", line 10, in <module>
ret = db.update( docs )

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/client.py",
line 764, in update
_, _, data = self.resource.post_json('_bulk_docs', body=content)

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 527, in post_json
**params)

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 546, in _request_json
headers=headers, **params)

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 542, in _request
credentials=self.credentials)

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 327, in request
resp = _try_request_with_retries(iter(self.retry_delays))

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 285, in _try_request_with_retries
return _try_request()

File "/usr/local/lib/python2.7/dist-packages/CouchDB-0.9-py2.7.egg/couchdb/http.py",
line 307, in _try_request
conn.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 812, in _send_output
msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xea in position 52:
ordinal not in range(128)


What version of the product are you using? On what operating system?

couchdb-python 0.9, ubuntu 12.04


Please provide any additional information below.

If the parameter to couchdb.Server is a str instead of a unicode object,
the script executes correctly.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

couchdb...@googlecode.com

unread,
Jul 6, 2014, 7:02:09 AM7/6/14
to couchdb...@googlegroups.com
Updates:
Status: WorksForMe

Comment #1 on issue 235 by djc.ochtman: Doc write exception with unicode
characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

I tried this test case and couldn't get it to fail on the current tip of
the default branch:

diff --git a/couchdb/tests/client.py b/couchdb/tests/client.py
--- a/couchdb/tests/client.py
+++ b/couchdb/tests/client.py
@@ -185,6 +185,10 @@
self.assertEqual(u'Iñtërnâtiônàlizætiøn', self.db[u'føø'][u'bår'])
self.assertEqual(u'ASCII', self.db[u'føø'][u'baz'])

+ def test_unicode_235(self):
+ doc = {u'type': 'test', u'val': unichr(40960)}
+ self.db.update([doc])
+
def test_disallow_nan(self):
try:
self.db['foo'] = {'number': float('nan')}

This makes me think this has been fixed already. If you can still reproduce
it with a more recent changeset, feel free to reopen.

couchdb...@googlecode.com

unread,
Jul 15, 2014, 2:26:42 AM7/15/14
to couchdb...@googlegroups.com

Comment #2 on issue 235 by mikebell...@gmail.com: Doc write exception with
unicode characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

"If the parameter to couchdb.Server is a str instead of a unicode object,
the script executes correctly."

In other words, the behaviour changes depending on whether the
couchdb.Server object is initialized with a string or a unicode string.

couchdb...@googlecode.com

unread,
Jul 15, 2014, 2:57:22 AM7/15/14
to couchdb...@googlegroups.com

Comment #3 on issue 235 by djc.ochtman: Doc write exception with unicode
characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

Right. Have you tried reproducing with current tip? Because I still can't.

couchdb...@googlecode.com

unread,
Jul 16, 2014, 2:14:17 PM7/16/14
to couchdb...@googlegroups.com

Comment #4 on issue 235 by hhmw56...@gmail.com: Doc write exception with
unicode characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

I have reproduced the problem in 0.10 and the latest couchdb-python from
github.

Looking at your test code it is not obvious to me that the Server object is
being initialized with a unicode string, which is necessary to trigger the
behavior I'm describing.

couchdb...@googlecode.com

unread,
Jul 26, 2014, 2:28:34 AM7/26/14
to couchdb...@googlegroups.com

Comment #5 on issue 235 by djc.ochtman: Doc write exception with unicode
characters
http://code.google.com/p/couchdb-python/issues/detail?id=235

This issue has been migrated to GitHub. Please continue discussion here:

https://github.com/djc/couchdb-python/issues/235
Reply all
Reply to author
Forward
0 new messages