title: Python Requests SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED - tlsv13 alert certificate required
body: <p>I am trying to create an HTTPS connection with a secured host and, even if I have the pem certificate (I have imported it from jks keystore file), I'm still receiving this error.</p>
  <p>[SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required</p>
  <p>So, this is the request:</p>
  <pre><code>import requests
  r = requests.patch(&quot;https://selfsigned_host:8080/myapp/v1/service/id/123&quot;, json={'another_field':'987654321'},verify='C:\\my_selfsigned_host.pem')
  </code></pre>
  <p>I have solved this by doing this solution from this <a href="https://gist.github.com/erikbern/756b1d8df2d1487497d29b90e81f8068" rel="nofollow noreferrer">Gist</a>:</p>
  <pre><code>import contextlib
  import OpenSSL.crypto
  import os
  import requests
  import ssl
  import tempfile
  import urllib3.contrib.pyopenssl
  
  @contextlib.contextmanager
  def pfx_to_pem(pfx_path, pfx_password):
      ''' Decrypts the .pfx file to be used with requests. '''
      with tempfile.NamedTemporaryFile(suffix='.pem',delete=False) as t_pem:
          f_pem = open(t_pem.name, 'wb')
          pfx = open(pfx_path, 'rb').read()
          p12 = OpenSSL.crypto.load_pkcs12(pfx, pfx_password)
          f_pem.write(OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, p12.get_privatekey()))
          f_pem.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, p12.get_certificate()))
          ca = p12.get_ca_certificates()
          if ca is not None:
              for cert in ca:
                  f_pem.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert))
          f_pem.close()
          yield t_pem.name
  </code></pre>
  <p>And I cloud reuse my pfx cert to make my request:</p>
  <pre><code>with pfx_to_pem('C:\\my_cert.pfx', 'my_pass') as cert:
       r = requests.patch(url,json=body,cert=cert, verify=False, headers=headers)
  </code></pre>
  <p>It works perfectly as I expect, but does anyone want to improve this solution?</p>