我试图通过python-cloudant连接到远程couchDB服务器,此服务器使用SSL证书。我无法访问服务器,因为我认为它无法捕获我的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()
我得到这个错误:
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:
当我使用下面的代码查看是否可以建立到服务器的连接时,它返回一个[200]响应,这意味着它可以访问它:
r = requests.get('https://xxx.xx.xxx.x', verify='catrust/',cert=('client01.crt', 'client01.key'))
注意,我在这里指定了“verify”和“cert”参数。
我的猜测是,Cloudant包中的请求无法捕获服务器的证书,我无法找到直接将couchDB指向这些参数的方法。
1条答案
按热度按时间ac1kyiln1#
如果有人还在纠结这个问题,我已经在Python-Cloudant Github存储库中发布了一个解决方案,你可以在这里找到它:https://github.com/cloudant/python-cloudant/issues/499