Score:0

Resolving the API Certificate Verification Failure in Python

gs flag

I am running several applications that use Python. No matter which application is used (and even if I execute the script directly within Python itself), certificate verification always fails, with code like this:

File "/usr/local/lib/python3.11/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/local/lib/python3.11/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.11/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.11/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.11/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.11/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.11/http/client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 1075, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.11/ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

I have installed certifi multiple times, reinstalled OpenSSL, python, pip, and the applications themselves, have manually created the certificates for the sites and placed them in the certificate folders... nothing resolves this issue. I am not using a VPN. How have you been able to get past this error?

cn flag
did `verify=false` not work?
001121100 avatar
gs flag
I am trying not to go that route. If I do, I would like to set it permanently and not just for a single instance. Which .py files would need to be altered?
Steffen Ullrich avatar
in flag
Unfortunately not enough is known about your environment. Is this problem for arbitrary sites, i.e. also google.com etc? Do you need to use a proxy for internet access in your environment? Does it work from the same machine with a browser and which certificate path is shown in the browser (i.e. the normal public CA or some CA pointing to TLS interception)?
Score:0
gs flag

I was finally able to force the programs to run within python by importing ssl and creating an unverified context.

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Still have not resolved the certificate problem, but at least I am able to move forward.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.