ABOUT ME

관심지식인 주식/정보처리기술사/IT개발/AI 관련 자료를 모아둔 지식창고 입니다.

Today
Yesterday
Total
  • pip package install SSL 인증서 Error 해결 (error: [SSL: CERTIFICATE_VERIFY_FAILED])
    python 2022. 5. 24. 15:45
    728x90
    반응형

    1. 증상 및 원인

    pip를 이용하여 원하는 패키지를 설치하려고 하면, 아래와 같은 에러가 발생할 수 있습니다. 주로 인트라넷을 사용하는 경우 아래와 같은 문제가 많이 발생합니다. 아래와 같은 에러가 발생하는 이유는 각 회사 컴퓨터에는 신뢰할 수 있는 루트 인증 기관을 가지고 있게 되는데, 인증 기관으로 python을 설치하기 위한 도메인을 포함하지 않은 경우에 이런 에러가 발생할 수 있습니다.

    $ pip install linkchecker
    Downloading/unpacking linkchecker
      Getting page https://pypi.python.org/simple/linkchecker/
      Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
      Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
      Getting page https://pypi.python.org/simple/
      Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(Host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ 
    
    $ pip install flask-bcrypt 
    Collecting flask-bcrypt
      WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-bcrypt/
      WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-bcrypt/
      WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-bcrypt/
      WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')"))': /simple/flask-bcrypt/
      WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-bcrypt/
      ERROR: Could not find a version that satisfies the requirement flask-bcrypt (from versions: none)
    ERROR: No matching distribution found for flask-bcrypt
    

    2. 간단한 해결 방법

    아래와 같은 명령어를 입력하여 문제를 해결할 수 있습니다.

    $ pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org 설치할패키지이름
    or
    $ python3 -m pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org 설치할패키지이름
    

    3. 영구적인 해결 방법

    3.1. 인증된 Host 등록하기

    위의 명령어는 하지만 pip를 위와 같이 입력해야 되는 문제점이 있기 때문에, 아래와 같은 방법으로 영구적으로 해결할 수 있습니다.

    $ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools
    

    아래와 같은 방법으로 python에 관련된 여러 신뢰할 수 있는 호스트에 추가해주어야 합니다. 신뢰할 수 있는 호스트와 프록시를 pip.ini (Windows) 또는 pip.conf (unix) 설정 파일에 추가합니다.

    [global]
    trusted-Host = pypi.python.org
                   pypi.org
                   files.pythonhosted.org
    

    3.2. Alias 등록하기

    alias란 복잡하거나 긴 명령어를 단순하게 약속된 단어로 사용하는 방법입니다. ~/.bashrc 파일을 열어 제일 마지막에 다음 내용을 추가했습니다.

    alias pip='pip --trusted-host pypi.org --trusted-host files.pythonhosted.org'
    

    출처

    728x90
    반응형
Designed by Tistory.