Hi Team, We are facing below error when we are connecting API .
Traceback (most recent call last):
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 1319, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
encode_chunked=req.has_header(‘Transfer-encoding’))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1338, in request
self._send_request(method, url, body, headers, encode_chunked)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1384, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1333, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1093, in _send_output
self.send(msg)
~~~~~~~~~^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1037, in send
self.connect()
~~~~~~~~~~~~^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\http\client.py”, line 1479, in connect
self.sock = self._context.wrap_socket(self.sock,
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
server_hostname=server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\ssl.py”, line 455, in wrap_socket
return self.sslsocket_class._create(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
sock=sock,
^^^^^^^^^^
…<5 lines>…
session=session
^^^^^^^^^^^^^^^
)
^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\ssl.py”, line 1076, in _create
self.do_handshake()
~~~~~~~~~~~~~~~~~^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\ssl.py”, line 1372, in do_handshake
self._sslobj.do_handshake()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1028)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 10, in
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\site-packages\fredapi\fred.py”, line 151, in get_series
root = self.__fetch_data(url)
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\site-packages\fredapi\fred.py”, line 84, in __fetch_data
response = urlopen(url)
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 189, in urlopen
return opener.open(url, data, timeout)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 489, in open
response = self._open(req, data)
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 506, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
‘_open’, req)
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 466, in _call_chain
result = func(*args)
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 1367, in https_open
return self.do_open(http.client.HTTPSConnection, req,
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
context=self._context)
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\testuser\AppData\Local\Programs\Python\Python313\Lib\urllib\request.py”, line 1322, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Missing Authority Key Identifier (_ssl.c:1028)>
You are using https to a host that does not have a valid certificate.
I believe this is failing due to create_default_context() requesting VERIFY_X509_STRICT. But I cannot be sure as you didn’t post the URL - please post it.
you can create a custom context, and remove the flag:
import ssl
context = ssl.create_default_context()
context.verify_flags &= ~ssl.VERIFY_X509_STRICT
urllib.request.urlopen(..., context=context)
ok , Let me check it