Scikit-learn: fetch_california_housing() URL였λ₯˜:<urlopen error="" certificate_verify_failed="" certificate="" verify="" failed=""/>

에 λ§Œλ“  2017λ…„ 11μ›” 25일  Β·  12μ½”λ©˜νŠΈ  Β·  좜처: scikit-learn/scikit-learn

μ„€λͺ…

fetch_california_housing()을 μ‚¬μš©ν•˜μ—¬ μƒ˜ν”Œ 데이터 μ„ΈνŠΈλ₯Ό λ‹€μš΄λ‘œλ“œν•  수 μ—†μŠ΅λ‹ˆλ‹€. μΈμ¦μ„œκ°€ 만료된 것 κ°™μŠ΅λ‹ˆκΉŒ?

μž¬ν˜„ν•  단계/μ½”λ“œ

print('scikit-learn 버전은 {}μž…λ‹ˆλ‹€.'.format(sklearn.__version__))
sklearn.datasetsμ—μ„œ κ°€μ Έμ˜€κΈ° fetch_california_housing
주택 = fetch_california_housing()

μ‹€μ œ κ²°κ³Ό

Downloading Cal. housing from https://ndownloader.figshare.com/files/5976036 to /Users/test/scikit_learn_data
The scikit-learn version is 0.19.1.
---------------------------------------------------------------------------
SSLError                                  Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1317                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318                           encode_chunked=req.has_header('Transfer-encoding'))
   1319             except OSError as err: # timeout error

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

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1284             body = _encode(body, 'body')
-> 1285         self.endheaders(body, encode_chunked=encode_chunked)
   1286 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
   1233             raise CannotSendHeader()
-> 1234         self._send_output(message_body, encode_chunked=encode_chunked)
   1235 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in send(self, data)
    963             if self.auto_open:
--> 964                 self.connect()
    965             else:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py in connect(self)
   1399             self.sock = self._context.wrap_socket(self.sock,
-> 1400                                                   server_hostname=server_hostname)
   1401             if not self._context.check_hostname and self._check_hostname:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    400                          server_hostname=server_hostname,
--> 401                          _context=self, _session=session)
    402 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context, _session)
    807                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 808                     self.do_handshake()
    809 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self, block)
   1060                 self.settimeout(None)
-> 1061             self._sslobj.do_handshake()
   1062         finally:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py in do_handshake(self)
    682         """Start the SSL/TLS handshake."""
--> 683         self._sslobj.do_handshake()
    684         if self.context.check_hostname:

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
<ipython-input-18-dc07bc139b51> in <module>()
      1 print('The scikit-learn version is {}.'.format(sklearn.__version__))
      2 from sklearn.datasets import fetch_california_housing
----> 3 housing = fetch_california_housing()

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/datasets/california_housing.py in fetch_california_housing(data_home, download_if_missing)
     99             ARCHIVE.url, data_home))
    100 
--> 101         archive_path = _fetch_remote(ARCHIVE, dirname=data_home)
    102 
    103         with tarfile.open(mode="r:gz", name=archive_path) as f:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/datasets/base.py in _fetch_remote(remote, dirname)
    872     file_path = (remote.filename if dirname is None
    873                  else join(dirname, remote.filename))
--> 874     urlretrieve(remote.url, file_path)
    875     checksum = _sha256(file_path)
    876     if remote.checksum != checksum:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in urlretrieve(url, filename, reporthook, data)
    246     url_type, path = splittype(url)
    247 
--> 248     with contextlib.closing(urlopen(url, data)) as fp:
    249         headers = fp.info()
    250 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    221     else:
    222         opener = _opener
--> 223     return opener.open(url, data, timeout)
    224 
    225 def install_opener(opener):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    524             req = meth(req)
    525 
--> 526         response = self._open(req, data)
    527 
    528         # post-process response

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in _open(self, req, data)
    542         protocol = req.type
    543         result = self._call_chain(self.handle_open, protocol, protocol +
--> 544                                   '_open', req)
    545         if result:
    546             return result

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    502         for handler in handlers:
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:
    506                 return result

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in https_open(self, req)
   1359         def https_open(self, req):
   1360             return self.do_open(http.client.HTTPSConnection, req,
-> 1361                 context=self._context, check_hostname=self._check_hostname)
   1362 
   1363         https_request = AbstractHTTPHandler.do_request_

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1318                           encode_chunked=req.has_header('Transfer-encoding'))
   1319             except OSError as err: # timeout error
-> 1320                 raise URLError(err)
   1321             r = h.getresponse()
   1322         except:

URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μœΌμ•…!

문제λ₯Ό μ°Ύμ•˜μŠ΅λ‹ˆλ‹€. Mac의 python 3.6μ—λŠ” μ„€μΉ˜ ν›„ 단계가 ν•„μš”ν•©λ‹ˆλ‹€.

$ less /Applications/Python\ 3.6/ReadMe.rtf

" 이전 λ¦΄λ¦¬μŠ€μ™€ 달리 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠλŠ” Apple 제곡 OpenSSL λΌμ΄λΈŒλŸ¬λ¦¬λŠ” 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ΄λŠ” λ˜ν•œ Keychain Access μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 및 λ³΄μ•ˆ λͺ…령쀄 μœ ν‹Έλ¦¬ν‹°κ°€ κ΄€λ¦¬ν•˜λŠ” μ‹œμŠ€ν…œ 및 μ‚¬μš©μž ν‚€μ²΄μΈμ˜ μ‹ λ’° μΈμ¦μ„œκ°€ 더 이상 κΈ°λ³Έκ°’μœΌλ‘œ μ‚¬μš©λ˜μ§€ μ•ŠμŒμ„ μ˜λ―Έν•©λ‹ˆλ‹€."

해결책은

$ sudo /Applications/Python\ 3.6/Install\ Certificates.command

λͺ¨λ“  12 λŒ“κΈ€

κΈ€μŽ„, λ‚˜λŠ” 그것이 맀우 μΌμ‹œμ μ΄κΈ°λ₯Ό λ°”λžλ‹ˆλ‹€. 그것은 μ—¬μ „νžˆ β€‹β€‹λ¬Έμ œμž…λ‹ˆκΉŒ?

μ•ˆλ…• Jnothman

λ‚˜λŠ” κΈˆμš”μΌμ— 이 문제λ₯Ό 처음 μ•Œμ•˜λ‹€. μ—¬μ „νžˆ 같은 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

URL였λ₯˜:

μ•ˆλΆ€

μ•€λ””

λ‚˜λŠ” 그런 λ¬Έμ œκ°€ μ—†μŠ΅λ‹ˆλ‹€. μ‹œκ³„κ°€ μ„€μ •λ˜μ–΄ μžˆμ§€ μ•Šμ€κ°€μš”?
잘λͺ»λ˜κ±°λ‚˜ λ­”κ°€?

μ•ˆλ…• Jnothman

μ €λŠ” λ§₯λΆν”„λ‘œλ₯Ό μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. λ‚΄ 컴퓨터에 ν‘œμ‹œλœ μ‹œκ°„μ΄ λ§žλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. 방금 μ½”λ“œλ₯Ό λ‹€μ‹œ μ‹€ν–‰ν–ˆλŠ”λ° λ™μΌν•œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

λ‚΄ μ‹œκ³„κ°€ μ˜¬λ°”λ₯΄κ²Œ μ„€μ •λ˜μ—ˆλŠ”μ§€ ν™•μΈν•˜λŠ” 방법을 μ•Œκ³  μžˆμŠ΅λ‹ˆκΉŒ?

μ•€λ””

λ‚˜λŠ” μ–ΈκΈ‰ν•˜λŠ” 것을 μžŠμ—ˆλ‹€. λ‚˜λŠ” μ½”λ“œλ₯Ό 보지 μ•Šμ•˜μ§€λ§Œ 이미 데이터 μ„ΈνŠΈλ₯Ό 둜컬 λ””μŠ€ν¬μ— λ‹€μš΄λ‘œλ“œν–ˆλ‹€λ©΄ μ‹€μ œλ‘œ κ°€μ Έμ˜€μ§€ μ•Šμ„ κ²ƒμ΄λ―€λ‘œ μ•„λ§ˆλ„ 그것이 당신을 μœ„ν•΄ μž‘λ™ν•˜λŠ” 이유일 κ²ƒμž…λ‹ˆλ‹€

μ΄μƒν•˜κ²Œλ„ ν™•μ‹€νžˆ μž¬ν˜„ν•  수 μ—†κ³  ~/scikit_learn_data μ—μ„œ cal_housing 데이터λ₯Ό μ‚­μ œν–ˆλŠ”μ§€ ν™•μΈν•˜μ—¬ scikit-learnμ—μ„œ λ¬Έμ œκ°€ λ˜μ§€ μ•ŠλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. λ‚˜λŠ” 이것을 닫을 κ²ƒμž…λ‹ˆλ‹€. @AEDWIP 문제λ₯Ό ν•΄κ²°ν•  수 μžˆλŠ” κ²½μš°μ— λŒ€λΉ„ν•˜μ—¬ μΆ”κ°€ 정보λ₯Ό μ œκ³΅ν•˜μ‹­μ‹œμ˜€.

λΉ„μŠ·ν•œ λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€ - Mac Book Pro, High Sierra.

이 SSL μΈμ¦μ„œμ— λŒ€ν•œ μ „λ¬Έκ°€λŠ” μ•„λ‹ˆμ§€λ§Œ μœ„μ—μ„œ μ–ΈκΈ‰ν•œ λŒ€λ‘œ 이것이 scikit-learnκ³Ό 관련이 μžˆλ‹€κ³  μƒκ°ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

이 μŠ€λ‹ˆνŽ«μ—μ„œ λ™μΌν•œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆκΉŒ?

from six.moves.urllib.request import urlretrieve
urlretrieve('https://ndownloader.figshare.com/files/5976036')

μœΌμ•…!

문제λ₯Ό μ°Ύμ•˜μŠ΅λ‹ˆλ‹€. Mac의 python 3.6μ—λŠ” μ„€μΉ˜ ν›„ 단계가 ν•„μš”ν•©λ‹ˆλ‹€.

$ less /Applications/Python\ 3.6/ReadMe.rtf

" 이전 λ¦΄λ¦¬μŠ€μ™€ 달리 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠλŠ” Apple 제곡 OpenSSL λΌμ΄λΈŒλŸ¬λ¦¬λŠ” 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ΄λŠ” λ˜ν•œ Keychain Access μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 및 λ³΄μ•ˆ λͺ…령쀄 μœ ν‹Έλ¦¬ν‹°κ°€ κ΄€λ¦¬ν•˜λŠ” μ‹œμŠ€ν…œ 및 μ‚¬μš©μž ν‚€μ²΄μΈμ˜ μ‹ λ’° μΈμ¦μ„œκ°€ 더 이상 κΈ°λ³Έκ°’μœΌλ‘œ μ‚¬μš©λ˜μ§€ μ•ŠμŒμ„ μ˜λ―Έν•©λ‹ˆλ‹€."

해결책은

$ sudo /Applications/Python\ 3.6/Install\ Certificates.command

Ubuntu 16.04의 python 3.6κ³Ό λ™μΌν•œ λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€.

μ—¬κΈ°μ—μ„œ μ†”λ£¨μ…˜μ„ μ°Ύμ•˜μŠ΅λ‹ˆλ‹€. http://blog.pengyifan.com/how-to-fix-python-ssl-certificate_verify_failed/

import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
    getattr(ssl, '_create_unverified_context', None)): 
    ssl._create_default_https_context = ssl._create_unverified_context

κ°μ‚¬ν•©λ‹ˆλ‹€. nfrik의 μ½”λ“œκ°€ μž‘λ™ν–ˆμŠ΅λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰