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.