본문 바로가기
파이썬/가상화폐

Binance WebSocket connection closed: connection was closed uncleanly ("SSL error: certificate verify failed (in tls_process_server_certificate)"), code: 1006 에러 해결방법

by 행복론자 2022. 7. 21.

Binance websocket 데이터가 필요해서 Binance 공식 repository에 있는 소스를 실행시켜봤습니다.

실행시킨 소스는 간단합니다.

import time
import logging
from binance.lib.utils import config_logging
from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient

config_logging(logging, logging.DEBUG)


def message_handler(message):
    print(message)


my_client = UMFuturesWebsocketClient()
my_client.start()

my_client.kline(
    symbol="btcusdt",
    id=12,
    interval="1d",
    callback=message_handler,
)

time.sleep(10)

logging.debug("closing ws connection")
my_client.stop()

 

 

그런데 실행하자마자 파이참에서 에러를 뱉어내네요

INFO:root:Connection with URL: wss://fstream.binance.com/ws
INFO:root:Start to connect....
WARNING:root:WebSocket connection closed: connection was closed uncleanly ("SSL error: certificate verify failed (in tls_process_server_certificate)"), code: 1006, clean: False, reason: connection was closed uncleanly ("SSL error: certificate verify failed (in tls_process_server_certificate)")
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
]. Retrying: 1
INFO:root:Start to connect....
WARNING:root:WebSocket connection closed: connection was closed uncleanly ("SSL error: certificate verify failed (in tls_process_server_certificate)"), code: 1006, clean: False, reason: connection was closed uncleanly ("SSL error: certificate verify failed (in tls_process_server_certificate)")
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
]. Retrying: 2
DEBUG:root:closing ws connection

 

 

찾아보니 다음처럼 해결할 수 있었습니다.

1.가상환경을 이용한다면 'anaconda activate 가상환경'을 이용해 진입합니다.

2.pip install certifi 를 입력합니다.

3.python -m certifi를 입력합니다.

4.그러면 경로가 나옵니다. 복사합니다.

 

5.windows 기준으로 시스템 환경변수 편집 > 환경변수 > 사용자 변수 추가로 다음과 같이

복사한 경로를 입력합니다.

 

 

6.그 다음 파이참(IDE)을 껐다가 재실행시키면 잘 동작합니다.

 

 

바이낸스 가이드 소스인데 실행시키지마자 에러나서 난감했는데 살짝 귀찮지만 그래도 빠르게 해결할 수 있었습니다.

 

 

* 참고한 해외 가이드: https://github.com/binance/binance-connector-python/issues/57

 

* 추가내용: 

그래도 실행하다 중간에 에러가 나네요

(DEBUG:root:closing ws connection
WARNING:root:WebSocket connection closed: connection was closed uncleanly ("peer dropped the TCP connection without previous WebSocket closing handshake"), code: 1006, clean: False, reason: connection was closed uncleanly ("peer dropped the TCP connection without previous WebSocket closing handshake")

 

이 부분에 대한 해결 방법은 .py 파일을 실행시키라는 것 같은데.. connector 말고 다른 방법을 사용해야겠습니다.

https://stackoverflow.com/questions/71884149/error-reactornotrestartable-twisted-internet-error-reactornotrestartable-bi

https://github.com/binance/binance-connector-python/issues/57

 

반응형
이 포스팅은 쿠팡파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

댓글