How to update cacerts.txt httplib2 for Github?

I am trying to use the Github API with httplib2. But when I make requests to its endpoints, it gives me the following error:

import httplib2 h = httplib2.Http() h.request('https://api.github.com/gists') # OUT: Traceback (most recent call last): # OUT: File "<input>", line 1, in <module> # OUT: File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1570, in request # OUT: (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) # OUT: File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1317, in _request # OUT: (response, content) = self._conn_request(conn, request_uri, method, body, headers) # OUT: File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1252, in _conn_request # OUT: conn.connect() # OUT: File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1044, in connect # OUT: raise SSLHandshakeError(e) # OUT: SSLHandshakeError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

I could use the following workaround:

 h = httplib2.Http(disable_ssl_certificate_validation=True) h.request('https://api.github.com/gists') # OUT: ({'content-length': '58443' ... 

But this is still a workaround, and I am wondering how to correctly verify the SSL certificate for Github using httplib2. A Google search, I found that I should update the cacerts.txt this library, but I donโ€™t know how and where to get the certificate for Github. Or is there another way to send requests via HTTPS without certificate verification issues?

+6
source share
1 answer

UPD: The easiest way is to open GitHub in Firefox, view page information โ†’ Security โ†’ Open certificate โ†’ Details โ†’ Export โ†’ as a PEM file. It is also better to use queries.

From the information that Firefox provides about https connectivity, I learned that the certificate for GitHub is โ€œDigiCert High Assurance EV Root CAโ€, which can be found here: http://curl.haxx.se/ca/cacert.pem

The certificate text can be inserted into httplib2.__path__ + '/cacerts.txt' or saved to a separate file, and the http connection must be created using

 h = httplib2.Http(ca_certs='/path/to/that/file') 

It is also helpful here to post about this in this section .

+4
source

Source: https://habr.com/ru/post/952919/


All Articles