couchDB , python and authentication

前端 未结 6 1679
一整个雨季
一整个雨季 2021-02-04 11:44

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\'         


        
6条回答
  •  情书的邮戳
    2021-02-04 12:26

    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

提交回复
热议问题