cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

Authentication doesn't work with CouchDB if option require_valid_user is enabled #387

Closed schferbe closed 6 years ago

schferbe commented 6 years ago

I want to connect to a CouchDB instance (example code below) with the configuration parameter

require_valid_user = true

this gives a

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://127.0.0.1:5984/_session

A hot fix for cookie based authentication would be:

diff --git a/src/cloudant/_client_session.py b/src/cloudant/_client_session.py
index 0e8fd38..d608f8e 100644
--- a/src/cloudant/_client_session.py
+++ b/src/cloudant/_client_session.py
@@ -148,6 +148,7 @@ class CookieSession(ClientSession):
             'POST',
             self._session_url,
             data={'name': self._username, 'password': self._password},
+            auth=(self._username, self._password)
         )
         resp.raise_for_status()

This doesn't work

from cloudant import CouchDB db = CouchDB(*auth, url='http://127.0.0.1:5984') db.connect() print(db.all_dbs())

tomblench commented 6 years ago

Cookie auth (_session) and require_valid_user isn't a supported combination. Our focus is on building a client for the Cloudant service, where require_valid_user is off and cannot be turned on.

That said, you are welcome to raise a PR with the above diff and we will be inclined to accept it providing all of our tests pass.

emlaver commented 6 years ago

Closing this issue. Please reopen if you raise a PR.

schferbe commented 4 years ago

I raised a PR now. Are the tests done automatically?