Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
This repository was 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

Description

@schferbe

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())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions