Skip to content

FIX: for SSLCertVerificationError on Mac OSX #15

@kodymoodley

Description

@kodymoodley

Hi,

For those on Mac OSX, you may receive an SSLCertVerificationError error when downloading the srl.pt tensorflow model. For example, when I run the following command stanza.Pipeline(lang='nl', processors='srl'), I get the following error:

Downloading https://raw.githubusercontent.com/stanfordnlp/stanza-resources/main/resources_1.4.0.json: 154kB [00:00, 33.1MB/s]
2022-05-19 15:09:31 INFO: Loading these models for language: nl (Dutch):
=======================
| Processor | Package |
-----------------------
| srl       | default |
=======================

2022-05-19 15:09:31 INFO: Use device: cpu
2022-05-19 15:09:31 INFO: Loading: srl
---------------------------------------------------------------------------
SSLCertVerificationError                  Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py:1350, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1349 try:
-> 1350     h.request(req.get_method(), req.selector, req.data, headers,
   1351               encode_chunked=req.has_header('Transfer-encoding'))
   1352 except OSError as err: # timeout error

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:1240, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1239 """Send a complete request to the server."""
-> 1240 self._send_request(method, url, body, headers, encode_chunked)

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:1286, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1285     body = _encode(body, 'body')
-> 1286 self.endheaders(body, encode_chunked=encode_chunked)

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:1235, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1234     raise CannotSendHeader()
-> 1235 self._send_output(message_body, encode_chunked=encode_chunked)

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:1006, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1005 del self._buffer[:]
-> 1006 self.send(msg)
   1008 if message_body is not None:
   1009 
   1010     # create a consistent interface to message_body

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:946, in HTTPConnection.send(self, data)
    945 if self.auto_open:
--> 946     self.connect()
    947 else:

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py:1409, in HTTPSConnection.connect(self)
   1407     server_hostname = self.host
-> 1409 self.sock = self._context.wrap_socket(self.sock,
   1410                                       server_hostname=server_hostname)

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    494 def wrap_socket(self, sock, server_side=False,
    495                 do_handshake_on_connect=True,
    496                 suppress_ragged_eofs=True,
    497                 server_hostname=None, session=None):
    498     # SSLSocket class handles server_hostname encoding before it calls
    499     # ctx._wrap_socket()
--> 500     return self.sslsocket_class._create(
    501         sock=sock,
    502         server_side=server_side,
    503         do_handshake_on_connect=do_handshake_on_connect,
    504         suppress_ragged_eofs=suppress_ragged_eofs,
    505         server_hostname=server_hostname,
    506         context=self,
    507         session=session
    508     )

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py:1040, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
   1039             raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1040         self.do_handshake()
   1041 except (OSError, ValueError):

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py:1309, in SSLSocket.do_handshake(self, block)
   1308         self.settimeout(None)
-> 1309     self._sslobj.do_handshake()
   1310 finally:

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

A fix that worked for me (OSX Monterey 12.3.1, M1 pro chip) is to run the following command in the terminal:

/Applications/Python\ 3.8/Install\ Certificates.command (replace 3.8 with the specific version of Python you are using)

More info here: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions