okfn-brasil / serenata-toolbox

📦 pip module containing code shared across Serenata de Amor's projects | ** Este repositório não recebe atualizações frequentes **
MIT License
154 stars 69 forks source link

Error: SSL: CERTIFICATE_VERIFY_FAILED #212

Closed WalnerPessoa closed 5 years ago

WalnerPessoa commented 5 years ago

What is the problem? The output is interrupted by an error and at there are no files in the data/.

``` !pip install -U serenata-toolbox from serenata_toolbox.datasets import Datasets datasets = Datasets('data/') # now lets see what are the latest datasets available for dataset in datasets.downloader.LATEST: print(dataset) # and you'll see a long list of datasets! # and let's download one of them datasets.downloader.download('2018-01-05-reimbursements.xz') # yay, you've just downloaded this dataset to data/ # you can also get the most recent version of all datasets: latest = list(datasets.downloader.LATEST) datasets.downloader.download(latest) --------------------------------------------------------------------------- SSLError Traceback (most recent call last) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in _wrap_create_connection(self, req, timeout, client_error, *args, **kwargs) 923 Tuple[asyncio.Transport, ResponseHandler], --> 924 await self._loop.create_connection(*args, **kwargs)) 925 except cert_errors as exc: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py in create_connection(self, protocol_factory, host, port, ssl, family, proto, flags, sock, local_addr, server_hostname) 802 transport, protocol = yield from self._create_connection_transport( --> 803 sock, protocol_factory, ssl, server_hostname) 804 if self._debug: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py in _create_connection_transport(self, sock, protocol_factory, ssl, server_hostname, server_side) 828 try: --> 829 yield from waiter 830 except: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py in data_received(self, data) 502 try: --> 503 ssldata, appdata = self._sslpipe.feed_ssldata(data) 504 except ssl.SSLError as e: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py in feed_ssldata(self, data, only_handshake) 200 # Call do_handshake() until it doesn't raise anymore. --> 201 self._sslobj.do_handshake() 202 self._state = _WRAPPED /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self) 688 """Start the SSL/TLS handshake.""" --> 689 self._sslobj.do_handshake() 690 if self.context.check_hostname: SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) The above exception was the direct cause of the following exception: ClientConnectorSSLError Traceback (most recent call last) in () 7 8 # and let's download one of them ----> 9 datasets.downloader.download('2018-01-05-reimbursements.xz') # yay, you've just downloaded this dataset to data/ 10 11 # you can also get the most recent version of all datasets: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serenata_toolbox/datasets/downloader.py in download(self, files) 76 77 loop = asyncio.get_event_loop() ---> 78 loop.run_until_complete(self.main(loop, files)) 79 80 async def main(self, loop, files): /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future) 465 raise RuntimeError('Event loop stopped before Future completed.') 466 --> 467 return future.result() 468 469 def stop(self): /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serenata_toolbox/datasets/downloader.py in main(self, loop, files) 88 # fetch total size (all files) 89 sizes = [self.fetch_size(client, f) for f in files] ---> 90 await asyncio.gather(*sizes) 91 92 # download /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serenata_toolbox/datasets/downloader.py in fetch_size(self, client, filename) 103 async def fetch_size(self, client, filename): 104 with (await self.semaphore): --> 105 async with client.head(self.url(filename)) as resp: 106 if resp.status != 200: 107 raise RemoteFileNotFound(self.url(filename)) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py in __aenter__(self) 1003 1004 async def __aenter__(self) -> _RetType: -> 1005 self._resp = await self._coro 1006 return self._resp 1007 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py in _request(self, method, str_or_url, params, data, json, cookies, headers, skip_auto_headers, auth, allow_redirects, max_redirects, compress, chunked, expect100, raise_for_status, read_until_eof, proxy, proxy_auth, timeout, verify_ssl, fingerprint, ssl_context, ssl, proxy_headers, trace_request_ctx) 474 req, 475 traces=traces, --> 476 timeout=real_timeout 477 ) 478 except asyncio.TimeoutError as exc: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in connect(self, req, traces, timeout) 520 521 try: --> 522 proto = await self._create_connection(req, traces, timeout) 523 if self._closed: 524 proto.close() /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in _create_connection(self, req, traces, timeout) 852 else: 853 _, proto = await self._create_direct_connection( --> 854 req, traces, timeout) 855 856 return proto /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in _create_direct_connection(self, req, traces, timeout, client_error) 990 else: 991 assert last_exc is not None --> 992 raise last_exc 993 994 async def _create_proxy_connection( /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in _create_direct_connection(self, req, traces, timeout, client_error) 972 server_hostname=hinfo['hostname'] if sslcontext else None, 973 local_addr=self._local_addr, --> 974 req=req, client_error=client_error) 975 except ClientConnectorError as exc: 976 last_exc = exc /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/connector.py in _wrap_create_connection(self, req, timeout, client_error, *args, **kwargs) 927 req.connection_key, exc) from exc 928 except ssl_errors as exc: --> 929 raise ClientConnectorSSLError(req.connection_key, exc) from exc 930 except OSError as exc: 931 raise client_error(req.connection_key, exc) from exc ClientConnectorSSLError: Cannot connect to host nyc3.digitaloceanspaces.com:443 ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)] ```

How can this be addressed? New comers might need help on how to approach or build a solution, maybe a step-by-step on how to address the issue can help

Who could help with this issue? We know sometimes a good session of pair programming can do wonders, maybe indicate someone that can be reached to help out and discuss ideas. If you don't know someone but is up for a pair programming session use this space to tell us o/

cuducos commented 5 years ago

Hi @WalnerPessoa, I edited your post just to include the error message, translate one or other sentence and included the error message in the title. This way if others run into this same issue, it would be easier for them to find this issue, and they have all the information available here, ok?

Anyway, from your post I understand you're using macOS's Python 3.6, which happens to have no SSL certificate at all. This StackOverflow answer might help you get around this issue, but I do recommend using pyenv to handle Python installations in macOS and Linux systems:

This isn't a solution to your specific problem, but I'm putting it here because this thread is the top Google result for "SSL: CERTIFICATE_VERIFY_FAILED", and it lead me on a wild goose chase.

If you have installed Python 3.6 on OSX and are getting the "SSL: CERTIFICATE_VERIFY_FAILED" error when trying to connect to an https:// site, it's probably because Python 3.6 on OSX has no certificates at all, and can't validate any SSL connections. This is a change for 3.6 on OSX, and requires a post-install step, which installs the certifi package of certificates. This is documented in the ReadMe, which you should find at /Applications/Python\ 3.6/ReadMe.rtf

The ReadMe will have you run this post-install script, which just installs certifi: /Applications/Python\ 3.6/Install\ Certificates.command

Release notes have some more info: https://www.python.org/downloads/release/python-360/

cuducos commented 5 years ago

Closed as requested by @WalnerPessoa