0

I try to read CSV from URL of the pandas dataframe, but it shows an error "SSLCertVerificationError ", how to deal with it? My laptop is M1 macOS, I'm not sure why. Here is my code:

import pandas as pd
path = "https://archive.ics.uci.edu/ml/machine-learning-databases/00523/Exasens.csv"
df = pd.read_csv(path, skiprows=3)

Here is error detail:

SSLCertVerificationError                  Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1347 try:
-> 1348     h.request(req.get_method(), req.selector, req.data, headers,
   1349               encode_chunked=req.has_header('Transfer-encoding'))
   1350 except OSError as err: # timeout error

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

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

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py:1277, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1276     raise CannotSendHeader()
-> 1277 self._send_output(message_body, encode_chunked=encode_chunked)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py:1037, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1036 del self._buffer[:]
-> 1037 self.send(msg)
   1039 if message_body is not None:
   1040 
   1041     # create a consistent interface to message_body

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py:975, in HTTPConnection.send(self, data)
    974 if self.auto_open:
--> 975     self.connect()
    976 else:

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py:1454, in HTTPSConnection.connect(self)
   1452     server_hostname = self.host
-> 1454 self.sock = self._context.wrap_socket(self.sock,
   1455                                       server_hostname=server_hostname)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py:513, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    507 def wrap_socket(self, sock, server_side=False,
    508                 do_handshake_on_connect=True,
    509                 suppress_ragged_eofs=True,
    510                 server_hostname=None, session=None):
    511     # SSLSocket class handles server_hostname encoding before it calls
    512     # ctx._wrap_socket()
--> 513     return self.sslsocket_class._create(
    514         sock=sock,
    515         server_side=server_side,
    516         do_handshake_on_connect=do_handshake_on_connect,
    517         suppress_ragged_eofs=suppress_ragged_eofs,
    518         server_hostname=server_hostname,
    519         context=self,
    520         session=session
    521     )

don't know how to solve it.

Lynn
  • 1
  • 3
  • Your code works for me; maybe your laptop does not / can not trust the source of the csv? You could try downloading the csv file manually and reading from disc instead – Chrysophylaxs Dec 26 '22 at 14:24
  • Thanks, mate, but the teacher has some requirements for this, only can read it from the URL, and can't download it. – Lynn Dec 26 '22 at 14:36
  • it works for me too , from error message its clear that it has problem with reading the URL socket ,so it might be the problem with your internet connection! try to see if you can open the file using a browser on your machine – eshirvana Dec 26 '22 at 17:00
  • I remember running in similar problems with the Python that came with Mac OS X. Its cert library was empty, hence it trusts no `https` site at all. You can follow instructions [here](https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error) to resolve it. Or you can install `pyenv` to manage multiple Python versions on the same development machine. – Code Different Dec 26 '22 at 20:55
  • 1
    I solved it with `pip install certifi` , `/Applications/Python\ 3.10/Install\ Certificates.command` – Lynn Dec 26 '22 at 21:26

0 Answers0