본문 바로가기
Python

Python - SSL warnings 출력 안하는/비활성화 방법

by 올엠 2024. 3. 7.
반응형

Python 에서 SSL 인증서를 비활성화 하면, 콘솔 화면에 경고가 출력하게 된다.

이를 비활성화 할 수 있는 방법 urllib3 와 SSLContext를 이용한 2가지 정도를 정리해 본다.

1. urllib3를 이용한 비활성화

import ssl
import urllib3


urllib3.disable_warnings()

ssl.urllib3.disable_warnings(category=category) 함수를 사용하여 특정 범주의 SSL 경고를 비활성화 할 수 있다.

  • urllib3.exceptions.InsecureRequestWarning: 안전하지 않은 요청에 대한 경고
  • urllib3.exceptions.InsecurePlatformWarning: 안전하지 않은 플랫폼에 대한 경고
  • urllib3.exceptions.InsecureHeaderWarning: 안전하지 않은 헤더에 대한 경고
  • urllib3.exceptions.InsecureContentEncodingWarning: 안전하지 않은 콘텐츠 인코딩에 대한 경고

1. ssl._create_default_https_context를 이용한 비활성화

import ssl

ssl._create_default_https_context = ssl.create_default_context(verify_mode=ssl.CERT_NONE)

 

 SSLContext를 만들고 verify_mode 매개변수를 CERT_NONE으로 설정하여 모든 SSL 인증서를 신뢰하도록 하면, SSL 경고가 출력되지 않는다.
 
 
 
 
반응형