Closed GoogleCodeExporter closed 9 years ago
Also 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 "<stdin>", line 1, in <module>
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?
Original comment by mich...@hinespot.com
on 5 Jun 2014 at 3:43
Also, 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
Original comment by mich...@hinespot.com
on 5 Jun 2014 at 4:30
Ah, 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.
Original comment by djc.ochtman
on 5 Jun 2014 at 7:18
Ummm, not quite fixed =). Here's the new result after doing 'hg update':
$ python
>>> db["foo"] = { "bar" : 1 }
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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'
Original comment by mich...@hinespot.com
on 5 Jun 2014 at 8:01
That'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).
Original comment by djc.ochtman
on 5 Jun 2014 at 8:16
Darn. 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.
Original comment by mich...@hinespot.com
on 6 Jun 2014 at 4:23
Original issue reported on code.google.com by
mich...@hinespot.com
on 5 Jun 2014 at 3:29