Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

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

Closed
schferbe opened this issue Jun 1, 2018 · 3 comments

Comments

@schferbe
Copy link

schferbe commented Jun 1, 2018

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()
  • Cloudant (python-cloudant) version(s) that are affected by this issue.
$ pip list | grep cloudant
cloudant (2.8.1)
  • Python version
$ python --version
Python 3.6.5
  • A small code sample that demonstrates the issue.
# This works
import requests
import json
auth = ('admin', '31sf13b3r!')
get_url = "http://127.0.0.1:5984/_session".format(auth[0])
r = requests.get(get_url, auth=auth)
print(json.dumps(r.json(), indent=1))


# 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
Copy link
Contributor

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.

schferbe added a commit to schferbe/python-cloudant that referenced this issue Jul 13, 2018
@emlaver
Copy link
Member

emlaver commented Jul 17, 2018

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

@emlaver emlaver closed this as completed Jul 17, 2018
@schferbe schferbe mentioned this issue Nov 25, 2019
3 tasks
@schferbe
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants