using self-signed certificates with requests in python
<p><strong>Situation :</strong>
The target site (a pre-prod URL, say <a href="https://my-pre-prod-site.com/login" rel="noreferrer">https://my-pre-prod-site.com/login</a>, for example) is using a self-signed certificate. 
From the browser, the site is accessible over https without any issues (the self-signed certificate warning is suppressed by adding the certificate to the trust store in the browser)</p>

<p><strong>Problem Statement :</strong>
A simple python script that makes a get call to the target site using requests fails with either of the below errors in different situations :</p>

<blockquote>
  <p>requests.exceptions.SSLError: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)</p>
</blockquote>

<p>or </p>

<blockquote>
  <p>requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
  The simple script used (on the python prompt) is :</p>
</blockquote>

<pre><code>import requests
res = requests.get('https://my-pre-prod-site.com/login')
</code></pre>

<p>**Things already tried **</p>

<ol>
<li>I do <strong>NOT</strong> want to skip the ssl verification. Hence, verify = false is not an option for me. </li>
<li>I have already used the below with the same error </li>
</ol>

<p><code>res = requests.get('https://my-pre-prod-site.com/login', verify = os.path.join(os.getcwd(),'test.pem')</code> where test.pem is a pem file created by concatenating the output of the below commands in that order :</p>

<blockquote>
  <p>openssl rsa -in ~/Desktop/CertPath/private.key -check</p>
</blockquote>

<p>and</p>

<blockquote>
  <p>openssl x509 -pubkey -noout -in ~/Desktop/CertPath/certificate.pem</p>
</blockquote>

<p>The script is run from ~/Desktop/CertPath so getcwd() gives the right path to the certificate.</p>

<ol start="3">
<li>I tried another test.pem file as well where the order of concatenation  was reversed. It still throws the same error. </li>
<li>Have tried passing the .pem file holding the public key and the .key file holding the private key, separately (individually) as well, with the same error as the outcome. </li>
</ol>

<p><strong>Environment details if it helps</strong></p>

<p>OS - ElCapitan Mac<br>
Requests - 2.9.0<br>
Python - 2.7.10<br>
OpenSSL being used by Python - 'OpenSSL 0.9.8zg 14 July 2015'</p>

<p>Note - The openssl version does not seem to be an issue. Because even with an updated version of openssl, the errors are the same - tested on Ubuntu 
with Python 2.6 that uses the Openssl 1.x</p>