让我先告诉你,我用谷歌搜索了一整天而且很多相似 问题及其解决方案。但不幸的是,这些都不可能 解决我的问题。
让我解释原因?
错误:
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)'),))
客户代码:
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)
应用代码:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__=='__main__':
app.run(debug=True)
使用ssl证书托管到nginx服务器的应用程序。 当我在上面运行 client.py 时。它无法连接和通过 python 2.x或3.x
中的SSLError(验证错误)但是如果我使用 verify = False 那么它会输出Hello World!随着 一些警告如下:
/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!
我想验证SSL证书不要忽略它或使用 验证=假。所以请你尽力帮助我。