How to change permissions on a couchdb database with python
Question: I am trying to add a user in the "_security" document of a database with
python-couchdb. I am getting an error because the "_security" document doesn't
have an "_id" attribute.

    
    
    import couchdb
    couch=couchdb.Server("http://admin:admin@localhost:5984")
    couch["db"]["_security"]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/couchdb/client.py", line 977, in __repr__
        return '<%s %r@%r %r>' % (type(self).__name__, self.id, self.rev,
      File "/usr/local/lib/python2.7/dist-packages/couchdb/client.py", line 987, in id
        return self['_id']
    KeyError: '_id'
    


Answer: The right way to do it is

    
    
    import couchdb
    couch=couchdb.Server("http://admin:admin@localhost:5984")
    db=couch["db"]
    security_doc=db.resource.get_json("_security")[2]
    db.resource.put("_security",{u'admins': {u'names': [u'admin1','admin2','admin3'], u'roles': []}, u'members': {u'names': [], u'roles': []}})
    

