
couchdb-python - issue #237
simple document creation works on couchdb, but not on mobile
What steps will reproduce the problem? 1. Start a couchbase-mobile database on Android and pull-replicate the data from a remote couchdb server to the phone. 2. pip install couchdb 0.9 3. Try create a simple document (no attachments)
What is the expected output? What do you see instead?
mrhines@mrhinesdev:~/mica$ python Python 2.7.5+ (default, Feb 27 2014, 19:39:55) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from couchdb import Server >>> s = Server("http://admin:super_secret_password@localhost:5984/") >>> db = s["mica"] >>> db["foo"] = { "bar" : "hello" } Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/couchdb/client.py", line 344, in setitem status, headers, data = resource.put_json(body=content) File "/usr/local/lib/python2.7/dist-packages/couchdb/http.py", line 531, in put_json **params) File "/usr/local/lib/python2.7/dist-packages/couchdb/http.py", line 547, in _request_json if 'application/json' in headers.get('content-type'): TypeError: argument of type 'NoneType' is not iterable >>>
This does work with couchdbkit (but I don't want to use couchdbkit!, I want to use couchdb-python!):
mrhines@mrhinesdev:~/mica$ python Python 2.7.5+ (default, Feb 27 2014, 19:39:55) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from couchdbkit import Server >>> s = Server("http://admin:super_secret_password@localhost:5984/") >>> db = s["mica"] >>> db["foo"] = { "bar" : "hello" } >>>
What version of the product are you using? On what operating system? $ sudo pip install couchdb (gets 0.9)
Please provide any additional information below.
If it helps, here's the output from my debugger showing the contents of the HTTP response of the document creation. I'm more than happy to get you anymore debug information that you like. Just let me know.
The Response code was: 200
content-type: application/json mime-version: 1.0 server: D. Rogatkin's TJWS with Android support (aka Acme.Serve)/Version 1.105, $Revision: 1.267 $,Couchbase Lite devbuild-0 date: Thu, 05 Jun 2014 03:25:47 GMT transfer-encoding: chunked connection: keep-alive keep-alive: timeout=30, max=100
Comment #1
Posted on Jun 5, 2014 by Happy GiraffeAlso the same problem on the master branch communicating with mobile REST api:
$ hg clone https://code.google.com/p/couchdb-python/ $ cd couchdb-python/ $ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import sys sys.path = ["."] + sys.path from couchdb import Server s = Server("http://admin:super_secret_password@localhost:5984") db = s["mica"] db["foo"] = {"bar" : "hello"} Traceback (most recent call last): File "", line 1, in File "./couchdb/client.py", line 350, in setitem status, headers, data = resource.put_json(body=content) File "./couchdb/http.py", line 541, in put_json **params) File "./couchdb/http.py", line 557, in _request_json if 'application/json' in headers.get('content-type'): TypeError: argument of type 'NoneType' is not iterable
Any ideas?
Comment #2
Posted on Jun 5, 2014 by Happy GiraffeAlso, here's the *working HTTP response from my real couchdb server:
Server: CouchDB/1.4.0 (Erlang OTP/R16B01) Location: http://localhost:5984/mica/foo2 ETag: "1-0b26fd22294459c090b330f5cae3e3b3" Date: Thu, 05 Jun 2014 04:29:25 GMT Content-Type: application/json Content-Length: 67 Cache-Control: must-revalidate
Comment #3
Posted on Jun 5, 2014 by Quick RhinoAh, that's a stupid bug. I pushed this oneliner to the default branch (rfe57285ec470):
diff --git a/couchdb/http.py b/couchdb/http.py --- a/couchdb/http.py +++ b/couchdb/http.py @@ -554,7 +554,7 @@ def _request_json(self, method, path=None, body=None, headers=None, **params): status, headers, data = self._request(method, path, body=body, headers=headers, **params) - if 'application/json' in headers.get('content-type'): + if 'application/json' in headers.get('content-type', ''): data = json.decode(data.read().decode('utf-8')) return status, headers, data
This will be in the next release, although that is still waiting for some further resolution of #231. Also, I would argue that couchbase-mobile is wrong for not providing the header in the first place.
Comment #4
Posted on Jun 5, 2014 by Happy GiraffeUmmm, not quite fixed =). Here's the new result after doing 'hg update':
$ python
db["foo"] = { "bar" : 1 } Traceback (most recent call last): File "", line 1, in File "./couchdb/client.py", line 350, in setitem status, headers, data = resource.put_json(body=content) File "./couchdb/http.py", line 541, in put_json **params) File "./couchdb/http.py", line 556, in _request_json headers=headers, **params) File "./couchdb/http.py", line 552, in _request credentials=self.credentials) File "./couchdb/http.py", line 392, in request data = json.decode(data.decode('utf-8')) AttributeError: 'ResponseBody' object has no attribute 'decode'
Comment #5
Posted on Jun 5, 2014 by Quick RhinoThat's probably a different bug, likely a regression due to the Python 3 porting effort in the default branch. However, that exception is a little weird, as it implies that you're trying to process an error response that is quite large (larger than 8k). It's also not covered by the test suite, apparently. Could you please open a new bug about it? It would be awesome if you could write a test case (see couchdb/tests) or other script that triggers this (ideally against a normal CouchDB server).
Comment #6
Posted on Jun 6, 2014 by Happy GiraffeDarn. I don't work for couchbase - so I'm not sure how I would write such a test case =(. But, I'll post on the couchbase community and see if they can help out.
Status: Fixed
Labels:
Type-Defect
Priority-Medium