4

I would like to authenticate to server from my client using certificate that is generated from server.I have a server-ca.crt and below is the CURL command that is working.How to send similar request using python requests module .

$ curl -X GET -u sat_username:sat_password \
-H "Accept:application/json" --cacert katello-server-ca.crt \
https://satellite6.example.com/katello/api/organizations

I have tried following way and it is getting some exception, can someone help in resolving this issue.

 python requestsCert.py
Traceback (most recent call last):
  File "requestsCert.py", line 2, in <module>
    res=requests.get('https://satellite6.example.com/katello/api/organizations', cert='/certificateTests/katello-server-ca.crt', verify=True)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 68, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 464, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL] PEM lib (_ssl.c:2554)
1
  • Closely related: stackoverflow.com/questions/30109449/… but I'm not sure that's a duplicate since in this question, the error is raised in requests code, whereas in the other question, requests is not involved.
    – David Z
    Commented Nov 18, 2017 at 10:04

1 Answer 1

5
res=requests.get('https://...', cert='/certificateTests/katello-server-ca.crt', verify=True)

The cert argument in requests.get is used to specify the client certificate and key which should be used for mutual authentication. It is not used to specify the trusted CA as the --cacert argument in curl does. Instead you should use the verify argument:

res=requests.get('https://...', verify='/certificateTests/katello-server-ca.crt')

For more information see SSL Cert Verification and Client Side Certificates in the documentation for requests.

Not the answer you're looking for? Browse other questions tagged or ask your own question.