Python

[Python] requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

비번변경 2022. 8. 10. 19:25

개요

시스템을 사용하는 사용자 목록을 확인하기 위해 아래와 같은 코드를 이용해 api 요청을 보내고자 한다.

import os
import requests

if __name__ == "__main__":
	HOST = 'www.example.com'
	token = 'TOKEN'
	headers = {'Authorization': 'token %s' % token}
	LIST_USER = os.path.join(HOST, 'api/users')
    
	r = requests.get(LIST_USER, headers=headers)

그러나 실행하니 requests.exceptions.SSLError 에러가 발생했다.

 

 

 

 

조치 1. 인증 비활성화

자체 서명한 인증서를 사용하여 인증서를 신뢰할 수 없을 때, 가장 간단한 조치 방법은 인증을 비활성화 하는 것이다.

requests.get('https://example.com', verify=False)

다만 이 방법은 man-in-the-middle 공격과 같은 보안 위험에 애플리케이션이 노출될 수 있다.

 

 

조치 2. 인증서 경로 전달

신뢰할 수 있는 인증서를 가지고 있다면, verify에 인증서의 경로를 전달하여 인증할 수 있다.

requests.get('https://example.com', verify='/path/to/certfile')

 

 

참고 문서

https://stackoverflow.com/questions/10667960/python-requests-throwing-sslerror

https://ngo.migrantok.org/bbs/board.php?bo_table=free&wr_id=842 

 

728x90