Why https connection can not be established?

29 views Asked by At

Background

I configured SSL certificate using ZeroSSL for my domain ('example.com', hereafter). I also configured nginx.conf and gunicorn and then the access to https://example.com/index.html on Chrome browser brings me back nginx welcome page. I thought an HTTPS access is successfully enabled on the browser. So I made a program to upload the file to this server using urllib3 but CERTIFICATE_VERIFY_FAILED error was raised. I want to fix this error.

Environment

  • Windows10(client)
  • AWS(server)
  • python v3.10.10
  • urllib3 v2.0.4
  • certifi v2023.7.22
  • nginx v1.22.1
  • gunicorn v21.2.0

Code (upload program)

import urllib3
import certifi

with open("filename.zip","rb") as f:
    fileObj = f.read()

proxy_headers = urllib3.util.make_headers(proxy_basic_auth=username+":"+password)
proxy = urllib3.ProxyManager(proxy_url="proxy address",
                             proxy_headers=proxy_headers,
                             ca_certs=certifi.where(),
                             timeout=urllib3.util.Timeout(connect=2.0, read=7.0))
res = proxy.request(method="POST",
                    url="https://example.com/",
                    fields={"uploadFile": ("filename.zip",
                                           fileObj,
                                           "application/zip")})

Code (gunicorn/Flask program)

from flask import Flask, request, make_response, jsonify
import werkzeug

app = Flask(__name__)

@app.route("/",methods=["POST","GET"])
def upload():
    UPLOAD_DIR = "/path/to/upload"

    file = request.files["uploadFile"]
    saveFileName = werkzeug.utils.secure_filename(file.filename)
    file.save(os.path.join(UPLOAD_DIR, saveFileName))

    return make_response(jsonify({"Result": "upload OK"}))

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8080)

Result

When I executed this program on command prompt, "CERTIFICATE_VERIFY_FAILED" error came up.

What I think

I embedded 'ca_certs=certifi.where()' parameter when creating a ProxyManager connection instance. My understanding is the reliability of SSL certificate for 'mysite.com' is verified by the collection of certificate authority provided by 'certifi.contents()'. Why this error came up ? What should I correct to fix this error ?

0

There are 0 answers