-
특정 도메인의 API를 사용시 발생하는 ssl certificate_verify_failed 오류설치&설정 관련 2020. 6. 29. 22:40728x90
특정 도메인의 API를 사용시 발생하는 ssl certificate_verify_failed 오류
https 통신시 발생을 합니다.
도메인이나 다른 문제가 없어 보이는테 이상하게 httpclient, axios로 통신을 시도하면 발생하는 문제입니다.
언어별로 해별방법이 비슷합니다.
python에서 해결 방법
import urllib.request import ssl def callApi(requst): context = ssl._create_unverified_context() r = urllib.request.urlopen('https://lahuman.github.com', context = context)
java에서 해결 방법
httpclient 4.4 이상을 사용하면 다음과 같이 쉽게 해결이 가능합니다.
void contextLoads() throws IOException { CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); HttpPost httpPost = new HttpPost("https://lahuman.github.com"); httpPost.addHeader("API-KEY","adsfasdfasdfasdfasdfasdf" ); httpPost.addHeader("Content-Type","application/json" ); httpPost.setEntity(new ByteArrayEntity(String.format("{\"ABC\":123}").getBytes())); try (CloseableHttpResponse response = httpClient.execute(httpPost)) { System.out.println(response.getStatusLine()); HttpEntity entity = response.getEntity(); String text = null; try (Scanner scanner = new Scanner(entity.getContent(), StandardCharsets.UTF_8.name())) { text = scanner.useDelimiter("\\A").next(); } System.out.println(text); EntityUtils.consume(entity); } catch (IOException e) { e.printStackTrace(); } }
nodejs에서 해결 방법
const https = require('https'); const axios = require('axios'); const instance = axios.create({ baseURL: 'https://lahuman.github.com', timeout: 120000, httpsAgent: new https.Agent({ rejectUnauthorized: false }) }); const response = await instance.post('/api', { abc:123 });
결론
결국 https의 Verifier를 사용하지 않는 옵션을 추가 한다.
728x90'설치&설정 관련' 카테고리의 다른 글
보안프로그램을 피해서 WSL 설치하기! (0) 2020.07.01 VS CODE에서 npm install 시 EACCESS 권한 오류 발생 (0) 2020.06.30 windows에 wsl 설치하고 설정하기 (0) 2020.06.28 Kubernetes Persistent Volumes 사용하기 (0) 2020.06.27 fluentd를 활용해 kubernetes 로그를 elasticsearch에 저장하고 kibana로 표출 해보자! (0) 2020.06.24