이슈 해결 모음
[Python] 공공데이터포털 OpenAPI 호출 에러 SSLError: HTTPSConnectionPool(host='apis.data.go.kr', port=443)
mndev
2025. 2. 6. 10:41
기존 공공데이터 API 화면에서 호출을 진행 했을 때는 수행이 잘 되다가 주피터노트북에서 호출하려고 보니 아래와 같은 에러가 발생하는 경우가 생겼다 ..
import requests
import chardet
import xml.etree.ElementTree as ET
import logging
# API 요청
url = 'https://apis.data.go.kr/1160100/service/GetFinaStatInfoService_V2/getSummFinaStat_V2'
serviceKey = ''
params = {'serviceKey': serviceKey, 'pageNo': '1', 'numOfRows': '10', 'resultType': 'xml', 'bizyear': '2024'}
response = requests.get(url, params=params)
detected_encoding = chardet.detect(response.content)['encoding']
logger.info(f"Detected Encoding: {detected_encoding}")
decoded_text = response.content.decode(detected_encoding)
SSLError: HTTPSConnectionPool(host='apis.data.go.kr', port=443)
---------------------------------------------------------------------------
SSLError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
467 try:
--> 468 self._validate_conn(conn)
469 except (SocketTimeout, BaseSSLError) as e:
18 frames
SSLError: [SSL: SSLV3_ALERT_ILLEGAL_PARAMETER] sslv3 alert illegal parameter (_ssl.c:1007)
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
SSLError: [SSL: SSLV3_ALERT_ILLEGAL_PARAMETER] sslv3 alert illegal parameter (_ssl.c:1007)
The above exception was the direct cause of the following exception:
MaxRetryError Traceback (most recent call last)
MaxRetryError: HTTPSConnectionPool(host='apis.data.go.kr', port=443): Max retries exceeded with url: /B552583/job/job_list_env?serviceKey= xx &pageNo=1&numOfRows=1000 (Caused by SSLError(SSLError(1, '[SSL: SSLV3_ALERT_ILLEGAL_PARAMETER] sslv3 alert illegal parameter (_ssl.c:1007)')))
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
515 if isinstance(e.reason, _SSLError):
516 # This branch is for urllib3 v1.22 and later.
--> 517 raise SSLError(e, request=request)
518
519 raise ConnectionError(e, request=request)
SSLError: HTTPSConnectionPool(host='apis.data.go.kr', port=443): Max retries exceeded with url: /B552583/job/job_list_env?serviceKey= xx &pageNo=1&numOfRows=1000 (Caused by SSLError(SSLError(1, '[SSL: SSLV3_ALERT_ILLEGAL_PARAMETER] sslv3 alert illegal parameter (_ssl.c:1007)')))
url에서 s를 빼고 호출하니 오류없이 정상적으로 실행되었다.
url = 'http://apis.data.go.kr/1160100/service/GetFinaStatInfoService_V2/getSummFinaStat_V2'