python cloudant couchDB SSL verification Failed

329 Views Asked by At

I'm trying to connect to a remote couchDB server through python-cloudant, this server uses an SSL certificate. I can't get access to the server as I think it fails to capture the certificate on my macOS.

from cloudant.client import Cloudant
from cloudant.client import CouchDB

client = CouchDB('myuser', 'mypassword', url='https://xxx.xx.xxx.xx', connect=True)

session = client.session()
print('Username: {0}'.format(session['userCtx']['name']))
print('Databases: {0}'.format(client.all_dbs()))

# Disconnect from the server
client.disconnect()

I get this error :

HTTPError                                 Traceback (most recent call last)
<ipython-input-57-e11f4f61f4aa> in <module>
      5 
      6 
----> 7 client = CouchDB('myuser', 'mypassword', url='https://xxx.xx.xxx.x', connect = True)
      8 
      9 

~/miniconda3/lib/python3.8/site-packages/cloudant/client.py in __init__(self, user, auth_token, admin_party, **kwargs)
    120         connect_to_couch = kwargs.get('connect', False)
    121         if connect_to_couch and self._DATABASE_CLASS == CouchDatabase:
--> 122             self.connect()
    123 
    124     @property

~/miniconda3/lib/python3.8/site-packages/cloudant/client.py in connect(self)
    188             self.r_session.headers.update(self._client_user_header)
    189 
--> 190         self.session_login()
    191 
    192         # Utilize an event hook to append to the response message

~/miniconda3/lib/python3.8/site-packages/cloudant/client.py in session_login(self, user, passwd)
    229         :param str auth_token: Authentication token used to connect to server.
    230         """
--> 231         self.change_credentials(user=user, auth_token=passwd)
    232 
    233     def change_credentials(self, user=None, auth_token=None):

~/miniconda3/lib/python3.8/site-packages/cloudant/client.py in change_credentials(self, user, auth_token)
    239         """
    240         self.r_session.set_credentials(user, auth_token)
--> 241         self.r_session.login()
    242 
    243     def session_logout(self):

~/miniconda3/lib/python3.8/site-packages/cloudant/_client_session.py in login(self)
    153             data={'name': self._username, 'password': self._password},
    154         )
--> 155         resp.raise_for_status()
    156 
    157     def logout(self):

~/miniconda3/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
    891 
    892         if http_error_msg:
--> 893             raise HTTPError(http_error_msg, response=self)
    894 
    895     def close(self):

HTTPError: 403 Client Error: Forbidden for url:

When I use the code below to see if I can establish a connection to the server, it returns a [200] response, which means it can access it:

r = requests.get('https://xxx.xx.xxx.x', verify='catrust/',cert=('client01.crt', 'client01.key'))

Note that I have specified here the 'verify' & 'cert' arguments.

My guess is that requests within the Cloudant package fails to capture the certificate of the server, I can't find a way to point couchDB to those arguments directly.

1

There are 1 best solutions below

0
On

Anyone still struggling with this, I've posted a solution in Python-Cloudant Github repository, you'll find it here : https://github.com/cloudant/python-cloudant/issues/499