Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 66250 invoked from network); 20 May 2008 18:47:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 May 2008 18:47:27 -0000 Received: (qmail 13842 invoked by uid 500); 20 May 2008 18:47:28 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 13818 invoked by uid 500); 20 May 2008 18:47:27 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 13807 invoked by uid 99); 20 May 2008 18:47:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2008 11:47:27 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ian.mulvany@gmail.com designates 74.125.46.157 as permitted sender) Received: from [74.125.46.157] (HELO yw-out-1718.google.com) (74.125.46.157) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2008 18:46:31 +0000 Received: by yw-out-1718.google.com with SMTP id 5so1558762ywr.0 for ; Tue, 20 May 2008 11:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; bh=B7yZTcY9A4XOKEQr5boRdq59VJOlioh66KxAJ+P/Bpw=; b=MdJWluXRiENFi7jCYa+RURtaNdvUHce6UPeiiFYWbitg6KVyLYNbfsKGCIUlDUL1Hk6OgZHTV7nFFeYvu8xvI7RKb8NbPJ6RIuaDNTPEx9k2n94e6iZj1yE7LAg0WtvfVj27Bipbrxja1MekpTowK4HbAVa1W9wEotsIljODcDU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=qswbZRBcRWamo7LOmTwMS6QJQTyCN9GO8llX34Dx7Q2SDxG3Ybn/9YvfIY6223EHQgg1HSg8P0dKrQwb0s933XGOq6yZrSPimKOTjPLfbrMnWi1/bSy63QA16RUbHKE1zfjNpHZZl6tTKQ/2kRmT8AAql8h75uByCApHi7xxuWE= Received: by 10.150.52.2 with SMTP id z2mr7962364ybz.48.1211309211179; Tue, 20 May 2008 11:46:51 -0700 (PDT) Received: by 10.151.8.21 with HTTP; Tue, 20 May 2008 11:46:51 -0700 (PDT) Message-ID: Date: Tue, 20 May 2008 19:46:51 +0100 From: "Ian Mulvany" Sender: ian.mulvany@gmail.com To: couchdb-user@incubator.apache.org Subject: couchdb-python: failing to 'PUT' document views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 2714a3be9f05eb5a X-Virus-Checked: Checked by ClamAV on apache.org Hi, I'd like to use the couchdb python API to insert views, but I am failing to understand the difference between a view and a document. I've installed couchdb on max osx 10.5 I followed the very nice instructions from http://blog.sweetspot.dm/tech-babble-resting-with-couchdb/ and using the documentation with the provided python api we have: import httplib, simplejson def prettyPrint(s): """Prettyprints the json response of an HTTPResponse object""" # HTTPResponse instance -> Python object -> str print simplejson.dumps(simplejson.loads(s.read()), sort_keys=True, indent=4) class Couch: """Basic wrapper class for operations on a couchDB""" def __init__(self, host, port=5984, options=None): self.host = host self.port = port def connect(self): return httplib.HTTPConnection(self.host, self.port) # No close() def createDb(self, dbName): """Creates a new database on the server""" r = self.put(''.join(['/',dbName,'/']), "") prettyPrint(r) def saveDoc(self, dbName, body, docId=None): """Save/create a document to/in a given database""" if docId: print ''.join(['/', dbName, '/', docId]) r = self.put(''.join(['/', dbName, '/', docId]), body) else: r = self.post(''.join(['/', dbName, '/']), body) prettyPrint(r) def put(self, uri, body): c = self.connect() if len(body) > 0: headers = {"Content-type": "application/json"} c.request("PUT", uri, body, headers) else: c.request("PUT", uri, body) return c.getresponse() # test creation of db and addition of doc foo = Couch('localhost', '5984') foo.createDb('testblog') doc = """ { "value": { "Subject":"I like Planktion", "Author":"Rusty", "type":"post", "PostedDate":"2006-08-15T17:30:12-04:00", "Tags":["plankton", "baseball", "decisions"], "Body":"I decided today that I don't like baseball. I like plankton." } } """ foo.saveDoc('testblog', doc, 'mypost') # this works, but now: view = """ { "language": "text/javascript", # also breaks when I omit this line "views": { "all": "function(doc) { if (doc.type == 'post') map(null, doc) }", "by_tags": "function(doc) { if (doc.type == 'post') map(doc.Tags, doc) }" } } """ foo.saveDoc('testblog', view, '_design/addview2') # does not work but provides the following error:ValueError: No JSON object could be decoded Any advice would be greatly appreciated, - Ian