1

Let Me first tell you that I googled it a whole day and many similar problems and their solutions. But unfortunately none of these can resolve my issue.

Let me explain why?

Error :

Traceback (most recent call last):
  File "/home/shafiq/PycharmProjects/venv/lib/python3.5/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/home/shafiq/PycharmProjects/venv/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/shafiq/PycharmProjects/venv/lib/python3.5/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='172.17.0.4', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(336265225, '[SSL] PEM lib (_ssl.c:2959)'),))

Client Code :

import ssl
import requests
import json
import certifi


def secureGet(url, params=None, headers=None):
    cert = certifi.where()
    return requests.get(url=url, params=params, headers=headers, cert=cert, verify=True)


def _process_response(response):
    try:
        text = json.loads(response.text) if response.text else {}
    except ValueError:
        return response.text
    else:
        if 'error' in text:
            # raise SSLError(status_code=text['error'])
            raise ssl.SSLError(status_code=text['error'])
    return text


url = 'https://172.17.0.4/'

resp_data = secureGet(url)
data = _process_response(resp_data)
print(data)

App Code :

from  flask import  Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello World!"



if __name__=='__main__':
    app.run(debug=True)

App hosted into a nginx server with ssl certificate. When I run client.py as it is above. it can't connect and through SSLError ( verification error) in both python 2.x or 3.x

But If I use verify=False then it give output Hello World! along with some warning as bellow

/home/shafiq/PycharmProjects/venv/lib/python3.5/site-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Hello World!

I want to verify SSL Certificate not to Ignore it or using verify=False. So Please help me your best.

  • Using `> ...` to format something as a citation should be done to format something as a citation **only** and not to give your own text a nice background. – Steffen Ullrich Mar 05 '18 at 14:16
  • *"Let Me first tell you that I googled it a whole day and many similar problems and their solutions. But unfortunately none of these can resolve my issue."* - in other words: I've tried something but I don't tell you what I've tried. Apart from that: looking at the documentation of the requests module and using the parameters as documented should have been sufficient. – Steffen Ullrich Mar 05 '18 at 14:20
  • There's a lot of similar question. I could not find the solution into these question answer. That's why I port this explaining step to step that could help me to get the right answer. I got a solution after posting this question but that solution yet not complete for me because it comply only CA certificate not self sign certificate. Now my question is, How could I verify self sign certificate using python? – Md Shafiqul Islam Mar 05 '18 at 14:24
  • Have you even read the question and answer I've marked as duplicate? Did you understand it? – Steffen Ullrich Mar 05 '18 at 14:25
  • Yes, Before you tag here. That solution does not work in my case. – Md Shafiqul Islam Mar 05 '18 at 14:27
  • Given that you make **exactly** the same mistake as shown in the answer I cannot imagine that you've read **and understood** the answer. – Steffen Ullrich Mar 05 '18 at 14:28

0 Answers0