tags:

views:

1143

answers:

4

I have installed couchDB v 0.10.0, and am attempting to talk to it via python from Couch class downloaded from couchDB wiki. Problem is:

Create database 'mydb': {'error': 'unauthorized', 'reason': 'You are not a server admin.'}

I hand edited the local.ini file to include my standard osx login and password. I now have full access via futon but no joy WRT python. Is this an http header issue?

At a a loss - thanks!

+3  A: 

The Couch class in the example does not pass any authentication information to the database, so it is not a miracle that it does not allow privileged operations. So your only options are:

  • disable authentication completely (as you mentioned)
  • pass the user name and password as part of the URI
  • pass the user name and password as an Authorization HTTP request header

If you want to pass a user name and a password, then you will need to change the Couch class. Sending an Authorization HTTP request header is easier, since the Couch class uses the httplib.HTTPConnection class. You can add such a header next to the Accept one this way:

headers = {
    "Accept": "application/json",
    "Authorization": "Basic " + 'username:password'.encode('base64')[:-1]}

Same for the other HTTP request methods.

The documentation on the basic authentication is here:

http://books.couchdb.org/relax/reference/security

fviktor
Documentation on the security features of CouchDB:http://wiki.apache.org/couchdb/Security_Features_Overview
fviktor
thanks for the thorough response fviktor.
idiotype
A: 

Don't forget to look at Couchdbkit (www.couchdbkit.org)

Pydroid
+1  A: 

You can also do:

db = couchdb.Database("http://your.url/yourdb")
db.resource.http.add_credentials(username, password)

after which all your requests should work.

thisfred
A: 

There are several patches for python-couchdb that enable authentication. The code probably will be included in Version 0.7 but until then you can usr teh fork at http://github.com/mdornseif/couchdb-python - it allows you to use http://user%[email protected]:5984/ type URLs.

http://blogs.23.nu/c0re/2009/12/running-a-couchdb-cluster-on-amazon-ec2/ (at the bottom) shows how to use CouchDB passwords.

mdorseif