관리 메뉴

솜씨좋은장씨

[Elasticsearch] elasticsearch.exceptions.SSLError: ConnectionError([SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)) 해결 방법 본문

Programming/Elasticsearch

[Elasticsearch] elasticsearch.exceptions.SSLError: ConnectionError([SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)) 해결 방법

솜씨좋은장씨 2021. 5. 14. 15:30
728x90
반응형

Python과 elasticsearch 라이브러리를 활용하여 es_client를 생성하고 elasticsearch에 검색식을 통해

결과를 받는 코드를 작성하였는데

Traceback (most recent call last):
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 706, in urlopen
     chunked=chunked,
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
     self._validate_conn(conn)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
     conn.connect()
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 421, in connect
     tls_in_tls=tls_in_tls,
   File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 432, in ssl_wrap_socket
     ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 474, in _ssl_wrap_socket_impl
     return ssl_context.wrap_socket(sock)
   File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
     _context=self, _session=session)
   File "/usr/lib/python3.6/ssl.py", line 817, in __init__
     self.do_handshake()
   File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
     self._sslobj.do_handshake()
   File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
     self._sslobj.do_handshake()
 ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/connection/http_urllib3.py", line 246, in perform_request
     method, url, body, retries=Retry(False), headers=request_headers, **kw
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 756, in urlopen
     method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
   File "/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py", line 506, in increment
     raise six.reraise(type(error), error, _stacktrace)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/packages/six.py", line 734, in reraise
     raise value.with_traceback(tb)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 706, in urlopen
     chunked=chunked,
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
     self._validate_conn(conn)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
     conn.connect()
   File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 421, in connect
     tls_in_tls=tls_in_tls,
   File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 432, in ssl_wrap_socket
     ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
   File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 474, in _ssl_wrap_socket_impl
     return ssl_context.wrap_socket(sock)
   File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
     _context=self, _session=session)
   File "/usr/lib/python3.6/ssl.py", line 817, in __init__
     self.do_handshake()
   File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
     self._sslobj.do_handshake()
   File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
     self._sslobj.do_handshake()
 urllib3.exceptions.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "./app.py", line 169, in check_es_data_by_frm_cd
     result = es_client.search(index=index_name, body=es_info.ES_FIND_BY_FRMCD_QUERY)
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/client/utils.py", line 152, in _wrapped
     return func(*args, params=params, headers=headers, **kwargs)
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/client/__init__.py", line 1663, in search
     body=body,
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/transport.py", line 390, in perform_request
     raise e
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/transport.py", line 365, in perform_request
     timeout=timeout,
   File "/usr/local/lib/python3.6/dist-packages/elasticsearch/connection/http_urllib3.py", line 255, in perform_request
     raise SSLError("N/A", str(e), e)
 elasticsearch.exceptions.SSLError: ConnectionError([SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852)) caused by: SSLError([SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:852))

위와 같은 오류가 발생했습니다.

 

원인은 es_client를 만들때 사용한 url이 https로 시작하는 것 때문이었습니다.

ES_ADRSS = f"https://{ES_IP}:{ES_PORT}"
es_client = Elasticsearch(ES_ADRSS, timeout=100, max_retries=10, retry_on_timeout=True)

 

해결 방법은 기존에 https로 시작했던 url을

# 기존
ES_ADRSS = f"https://{ES_IP}:{ES_PORT}"

# 변경
ES_ADRSS = f"http://{ES_IP}:{ES_PORT}"
# or
ES_ADRSS = f"{ES_IP}:{ES_PORT}"

http로 바꾸거나 없애면 됩니다.

 

읽어주셔서 감사합니다.

Comments