Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run any websocket example #57

Closed
Kenisy opened this issue Jun 21, 2021 · 20 comments
Closed

Can't run any websocket example #57

Kenisy opened this issue Jun 21, 2021 · 20 comments
Labels
reviewing reviewing the issue

Comments

@Kenisy
Copy link

Kenisy commented Jun 21, 2021

Normal spot examples run fine but when I run any websocket example I get this error:

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

Could you help me fix this issue ?

@2pd
Copy link
Contributor

2pd commented Jun 21, 2021

thanks for your feedback, please share a few info:

  • what's your python version
  • did you install all packages from requirements.txt

@Kenisy
Copy link
Author

Kenisy commented Jun 22, 2021

My python version is 3.7.10
I used pip install binance-connector so I guess all packages are installed.

@victorvalentee
Copy link

victorvalentee commented Jun 25, 2021

Having the same problem here. I'm attaching an example code, so the issue can be reproducible.

import time
from binance.websocket.spot.websocket_client import SpotWebsocketClient


if __name__ == '__main__':
    # Initialize binance client.
    binance_stream_client = SpotWebsocketClient()

    # Start listening to stream.
    binance_stream_client.start()

    # Get new ticker data from stream.
    binance_stream_client.trade(symbol="BTCUSDT", id=1, callback=print)

    # Wait.
    time.sleep(5)

    # Stop listening to stream.
    binance_stream_client.stop()

After I start listening to the stream, all I get is this error:

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

It seems to be failing on the SSL certificate verification.

Update: I'm running Python 3.8.3 on Windows 10.

@kooltux
Copy link

kooltux commented Jun 25, 2021

Same here on openSUSE using pip3 install on latest branch I think. It's even worse: the module binance.websocket.spot.websocket_client is not found. That may be a different issue so I don't want to pollute this one :)

Running on openSUSE 15.2 up-to-date with python 3.6.12 (yeah,; I know.... this is old and soon EOL. But this is what I see :))

@2pd 2pd added the reviewing reviewing the issue label Jun 28, 2021
@phoe8lin
Copy link

Get the key from https://testnet.binancefuture.com/cn/futures/BTCUSDT , still cant get the listenkey via client.new_listen_key()
image

@2pd
Copy link
Contributor

2pd commented Jul 13, 2021

Get the key from https://testnet.binancefuture.com/cn/futures/BTCUSDT , still cant get the listenkey via client.new_listen_key()
image

This library is not support futures yet, so the futures testnet api key will not working here.

@chairz
Copy link
Contributor

chairz commented Jul 13, 2021

Normal spot examples run fine but when I run any websocket example I get this error:

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

Could you help me fix this issue ?

This is a known issue with pyOpenSSL package on windows. The bug is that twisted does not includes a trust root sets of its own. The workaround here is by using certifi and setting the correct environment variable for twisted manually. This is the API documentation about the environment variable(SSL_CERT_FILE) to set for twisted.

If you run the file from cmd,

pip install certifi
for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
python example.py

if you run the file on an IDE e.g pycharm,

  1. pip install certifi
  2. Get the file path of cacert.pem file by running python -m certifi
  3. Copy the file path of cacert.pen and set the Environment Variables for SSL_CERT_FILE. These are the steps to setup environment variable on windows.
  4. Restart IDE and run the websocket example

P.S: I did these by using PyCharm and PyCharm imports environment variables automatically when running the project. If you are using other IDEs, please ensure that the project runs with the system's environment variables.

@phoe8lin
Copy link

Get the key from https://testnet.binancefuture.com/cn/futures/BTCUSDT , still cant get the listenkey via client.new_listen_key()
image

This library is not support futures yet, so the futures testnet api key will not working here.

What about production futures? Can i have my real api key working here?

@2pd
Copy link
Contributor

2pd commented Jul 14, 2021

Futures (testnet and production) is not supported by this library.

@RT-Tap
Copy link

RT-Tap commented Jul 17, 2021

Reporting in that I have the same issue , mainly trying manage_local_order_book.py on testnet and production and posted about it here before finding this. Can I delete my other post (it looks like I can only close it)? I don't get the issue running my code which utilizes requests and websocket-client.

So from what I understand binance-connector just doesn't work on Windows because of the twisted library it's based on? Is there a known fix I am missing? I also tried running on WSL (Windows subsystem for linux) because I found somewhere that this is a Windows only issue, but that didn't work either so now im onto trying on a virtual machine but I have to wonder why an official library doesn't work on a certain OS without expressly saying that it doesn't or why base your library around another library that is known to have SSL issues when dealing with thangs that handle money.

I tried the below fix, along with other fixes based on the same principal I found on stack overflow but none work, I just got another error, posted below that.

Normal spot examples run fine but when I run any websocket example I get this error:

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

Could you help me fix this issue ?

This is a known issue with pyOpenSSL package on windows. The bug is that twisted does not includes a trust root sets of its own. The workaround here is by using certifi and setting the correct environment variable for twisted manually. This is the API documentation about the environment variable(SSL_CERT_FILE) to set for twisted.

If you run the file from cmd,

pip install certifi
for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
python example.py

if you run the file on an IDE e.g pycharm,

  1. pip install certifi
  2. Get the directory of cacert.pem file by running python -m certifi
  3. Copy the directory path and set the Environment Variables for SSL_CERT_FILE. These are the steps to setup environment variable on windows.
  4. Restart IDE and run the websocket example

P.S: I did these by using PyCharm and PyCharm imports environment variables automatically when running the project. If you are using other IDEs, please ensure that the project runs with the system's environment variables.

And the output/result of trying what is mentioned in the above post I get:

INFO:root:Connection with URL: wss://stream.binance.com:9443/ws
INFO:root:Start to connect....
INFO:root:Server connected
INFO:root:Sending message to Server: b'{"method": "SUBSCRIBE", "params": ["bnbusdt@depth@1000ms"], "id": 1}'
INFO:root:Out of sync, re-syncing...
Unhandled Error
Traceback (most recent call last):
  Edited to shorten and remove useless lines
   File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 83, in callWithContext        
     return func(*args, **kw)
--- <exception caught here> ---

  Edited to shorten and remove useless lines

 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 169, in _handle_exception
   raise ClientError(status_code, err["code"], err["msg"], response.headers)
binance.error.ClientError: (400, -1100, "Illegal characters found in parameter 'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:53 GMT', 'Server': 'nginx', 'x-mbx-uuid': '37314be0-3771-4783-8951-9ebb62702e69', 'x-mbx-used-weight': '10', 'x-mbx-used-weight-1m': '10', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': 'qZURovNxawROHm0E6JoSd30cyTk-mV2cb_5d_9t5AcIhFlpI_Ijszw=='})

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)
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback: <class 'binance.error.ClientError'>: (400, -1100, "Illegal characters found in parameter 
'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:53 GMT', 'Server': 'nginx', 'x-mbx-uuid': '37314be0-3771-4783-8951-9ebb62702e69', 'x-mbx-used-weight': '10', 'x-mbx-used-weight-1m': '10', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': 'qZURovNxawROHm0E6JoSd30cyTk-mV2cb_5d_9t5AcIhFlpI_Ijszw=='})


 Edited to shorten and remove useless lines


} Retrying 1 ...
INFO:root:Start to connect....
INFO:root:Server connected

@chairz
Copy link
Contributor

chairz commented Jul 19, 2021

Reporting in that I have the same issue , mainly trying manage_local_order_book.py on testnet and production and posted about it here before finding this. Can I delete my other post (it looks like I can only close it)? I don't get the issue running my code which utilizes requests and websocket-client.

So from what I understand binance-connector just doesn't work on Windows because of the twisted library it's based on? Is there a known fix I am missing? I also tried running on WSL (Windows subsystem for linux) because I found somewhere that this is a Windows only issue, but that didn't work either so now im onto trying on a virtual machine but I have to wonder why an official library doesn't work on a certain OS without expressly saying that it doesn't or why base your library around another library that is known to have SSL issues when dealing with thangs that handle money.

I tried the below fix, along with other fixes based on the same principal I found on stack overflow but none work, I just got another error, posted below that.

Normal spot examples run fine but when I run any websocket example I get this error:

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

Could you help me fix this issue ?

This is a known issue with pyOpenSSL package on windows. The bug is that twisted does not includes a trust root sets of its own. The workaround here is by using certifi and setting the correct environment variable for twisted manually. This is the API documentation about the environment variable(SSL_CERT_FILE) to set for twisted.
If you run the file from cmd,

pip install certifi
for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
python example.py

if you run the file on an IDE e.g pycharm,

  1. pip install certifi
  2. Get the directory of cacert.pem file by running python -m certifi
  3. Copy the directory path and set the Environment Variables for SSL_CERT_FILE. These are the steps to setup environment variable on windows.
  4. Restart IDE and run the websocket example

P.S: I did these by using PyCharm and PyCharm imports environment variables automatically when running the project. If you are using other IDEs, please ensure that the project runs with the system's environment variables.

And the output/result of trying what is mentioned in the above post I get:

INFO:root:Connection with URL: wss://stream.binance.com:9443/ws
INFO:root:Start to connect....
INFO:root:Server connected
INFO:root:Sending message to Server: b'{"method": "SUBSCRIBE", "params": ["bnbusdt@depth@1000ms"], "id": 1}'
INFO:root:Out of sync, re-syncing...
Unhandled Error
Traceback (most recent call last):
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
   return callWithContext({"system": lp}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
   return context.call({ILogContext: newCtx}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 118, in callWithContext       
   return self.currentContext().callWithContext(ctx, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 83, in callWithContext        
   return func(*args, **kw)
--- <exception caught here> ---
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
   why = getattr(selectable, method)()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 246, in doRead
   return self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 251, in _dataReceived
   rval = self.protocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 324, in dataReceived
   self._flushReceiveBIO()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
   ProtocolWrapper.dataReceived(self, bytes)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
   self.wrappedProtocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
   self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
   self.consumeData()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
   while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1579, in processData
   fr = self.onFrameEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1704, in onFrameEnd
   self._onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 318, in _onMessageEnd
   self.onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 628, in onMessageEnd
   self._onMessage(payload, self.message_is_binary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 321, in _onMessage
   self.onMessage(payload, isBinary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py", line 30, in onMessage
   self.factory.callback(payload_obj)
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 113, in message_handler
   order_book = get_snapshot()
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 44, in get_snapshot
   return client.depth(symbol, limit=1000)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py", line 62, in depth
   return self.query("/api/v3/depth", params)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 67, in query
   return self.send_request("GET", url_path, payload=payload)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 116, in send_request
   self._handle_exception(response)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 169, in _handle_exception
   raise ClientError(status_code, err["code"], err["msg"], response.headers)
binance.error.ClientError: (400, -1100, "Illegal characters found in parameter 'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:53 GMT', 'Server': 'nginx', 'x-mbx-uuid': '37314be0-3771-4783-8951-9ebb62702e69', 'x-mbx-used-weight': '10', 'x-mbx-used-weight-1m': '10', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': 'qZURovNxawROHm0E6JoSd30cyTk-mV2cb_5d_9t5AcIhFlpI_Ijszw=='})

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)
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback: <class 'binance.error.ClientError'>: (400, -1100, "Illegal characters found in parameter 
'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:53 GMT', 'Server': 'nginx', 'x-mbx-uuid': '37314be0-3771-4783-8951-9ebb62702e69', 'x-mbx-used-weight': '10', 'x-mbx-used-weight-1m': '10', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': 'qZURovNxawROHm0E6JoSd30cyTk-mV2cb_5d_9t5AcIhFlpI_Ijszw=='})
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py:85:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:118:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:83:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:154:_doReadOrWrite
--- <exception caught here> ---
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:149:_doReadOrWrite
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:246:doRead
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:251:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:324:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:290:_flushReceiveBIO
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py:107:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:290:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1207:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1219:consumeData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1579:processData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1704:onFrameEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:318:_onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:628:onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:321:_onMessage
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py:30:onMessage
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:113:message_handler
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:44:get_snapshot
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py:62:depth
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:67:query
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:116:send_request
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:169:_handle_exception
]. Retrying: 1
INFO:root:Start to connect....
INFO:root:Server connected
INFO:root:Sending message to Server: b'{"method": "SUBSCRIBE", "params": ["bnbusdt@depth@1000ms"], "id": 1}'
INFO:root:Out of sync, re-syncing...
Unhandled Error
Traceback (most recent call last):
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
   return callWithContext({"system": lp}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
   return context.call({ILogContext: newCtx}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
   return self.currentContext().callWithContext(ctx, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
   return func(*args, **kw)
--- <exception caught here> ---
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
   why = getattr(selectable, method)()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 246, in doRead
   return self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 251, in _dataReceived
   rval = self.protocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 324, in dataReceived
   self._flushReceiveBIO()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
   ProtocolWrapper.dataReceived(self, bytes)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
   self.wrappedProtocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
   self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
   self.consumeData()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
   while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1579, in processData
   fr = self.onFrameEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1704, in onFrameEnd
   self._onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 318, in _onMessageEnd
   self.onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 628, in onMessageEnd
   self._onMessage(payload, self.message_is_binary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 321, in _onMessage
   self.onMessage(payload, isBinary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py", line 30, in onMessage
   self.factory.callback(payload_obj)
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 113, in message_handler
   order_book = get_snapshot()
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 44, in get_snapshot
   return client.depth(symbol, limit=1000)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py", line 62, in depth
   return self.query("/api/v3/depth", params)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 67, in query
   return self.send_request("GET", url_path, payload=payload)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 116, in send_request
   self._handle_exception(response)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 169, in _handle_exception
   raise ClientError(status_code, err["code"], err["msg"], response.headers)
binance.error.ClientError: (400, -1100, "Illegal characters found in parameter 'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:55 GMT', 'Server': 'nginx', 'x-mbx-uuid': '445ab778-0ab8-4f40-8af8-e5d9e6a4f999', 'x-mbx-used-weight': '20', 'x-mbx-used-weight-1m': '20', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': '4faZidhf8wWviFjFc2fzeic2huAk4mzhRCnY2o-cXAh8laeL1eEFzg=='})

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)
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback: <class 'binance.error.ClientError'>: (400, -1100, "Illegal characters found in parameter 
'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:55 GMT', 'Server': 'nginx', 'x-mbx-uuid': '445ab778-0ab8-4f40-8af8-e5d9e6a4f999', 'x-mbx-used-weight': '20', 'x-mbx-used-weight-1m': '20', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': '4faZidhf8wWviFjFc2fzeic2huAk4mzhRCnY2o-cXAh8laeL1eEFzg=='})
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py:85:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:118:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:83:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:154:_doReadOrWrite
--- <exception caught here> ---
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:149:_doReadOrWrite
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:246:doRead
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:251:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:324:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:290:_flushReceiveBIO
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py:107:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:290:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1207:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1219:consumeData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1579:processData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1704:onFrameEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:318:_onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:628:onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:321:_onMessage
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py:30:onMessage
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:113:message_handler
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:44:get_snapshot
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py:62:depth
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:67:query
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:116:send_request
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:169:_handle_exception
]. Retrying: 1
INFO:root:Start to connect....
Traceback (most recent call last):
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 147, in <module>
   main()
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 143, in main
   loop.run_until_complete(asyncio.gather(listen_ws(), get_best_price()))
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\base_events.py", line 629, in run_until_complete
   self.run_forever()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\windows_events.py", line 316, in run_forever
   super().run_forever()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\base_events.py", line 596, in run_forever
   self._run_once()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\base_events.py", line 1854, in _run_once
   event_list = self._selector.select(timeout)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\windows_events.py", line 434, in select
   self._poll(timeout)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\asyncio\windows_events.py", line 783, in _poll
   status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
KeyboardInterrupt
INFO:root:Server connected
INFO:root:Sending message to Server: b'{"method": "SUBSCRIBE", "params": ["bnbusdt@depth@1000ms"], "id": 1}'
INFO:root:Out of sync, re-syncing...
Unhandled Error
Traceback (most recent call last):
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
   return callWithContext({"system": lp}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
   return context.call({ILogContext: newCtx}, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
   return self.currentContext().callWithContext(ctx, func, *args, **kw)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
   return func(*args, **kw)
--- <exception caught here> ---
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
   why = getattr(selectable, method)()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 246, in doRead
   return self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py", line 251, in _dataReceived
   rval = self.protocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 324, in dataReceived
   self._flushReceiveBIO()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
   ProtocolWrapper.dataReceived(self, bytes)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
   self.wrappedProtocol.dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
   self._dataReceived(data)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
   self.consumeData()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
   while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1579, in processData
   fr = self.onFrameEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 1704, in onFrameEnd
   self._onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 318, in _onMessageEnd
   self.onMessageEnd()
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py", line 628, in onMessageEnd
   self._onMessage(payload, self.message_is_binary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py", line 321, in _onMessage
   self.onMessage(payload, isBinary)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py", line 30, in onMessage
   self.factory.callback(payload_obj)
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 113, in message_handler
   order_book = get_snapshot()
 File "C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py", line 44, in get_snapshot
   return client.depth(symbol, limit=1000)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py", line 62, in depth
   return self.query("/api/v3/depth", params)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 67, in query
   return self.send_request("GET", url_path, payload=payload)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 116, in send_request
   self._handle_exception(response)
 File "C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py", line 169, in _handle_exception
   raise ClientError(status_code, err["code"], err["msg"], response.headers)
binance.error.ClientError: (400, -1100, "Illegal characters found in parameter 'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:57 GMT', 'Server': 'nginx', 'x-mbx-uuid': 'cdf0a88e-efd8-43ed-81a7-16f36eed05ce', 'x-mbx-used-weight': '30', 'x-mbx-used-weight-1m': '30', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': '85zvmUmomhn009Gf0bLQPBMRh8508BVwGSwWtaR7NcMggQNsi-atHA=='})

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)
ERROR:root:Lost connection to Server. Reason: [Failure instance: Traceback: <class 'binance.error.ClientError'>: (400, -1100, "Illegal characters found in parameter 
'symbol'; legal range is '^[A-Z0-9-_.]{1,20}$'.", {'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '108', 'Connection': 'keep-alive', 'Date': 'Sat, 17 Jul 2021 23:44:57 GMT', 'Server': 'nginx', 'x-mbx-uuid': 'cdf0a88e-efd8-43ed-81a7-16f36eed05ce', 'x-mbx-used-weight': '30', 'x-mbx-used-weight-1m': '30', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 33193046475e96dea23c35606f55483e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MIA3-C2', 'X-Amz-Cf-Id': '85zvmUmomhn009Gf0bLQPBMRh8508BVwGSwWtaR7NcMggQNsi-atHA=='})
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\log.py:85:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:118:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\python\context.py:83:callWithContext
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:154:_doReadOrWrite
--- <exception caught here> ---
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\selectreactor.py:149:_doReadOrWrite
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:246:doRead
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\internet\tcp.py:251:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:324:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\tls.py:290:_flushReceiveBIO
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\twisted\protocols\policies.py:107:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:290:dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1207:_dataReceived
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1219:consumeData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1579:processData
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:1704:onFrameEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:318:_onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\websocket\protocol.py:628:onMessageEnd
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\autobahn\twisted\websocket.py:321:_onMessage
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\websocket\binance_client_protocol.py:30:onMessage
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:113:message_handler
C:\Users\Artyt\Documents\Python Scripts\manage_local_order_book.py:44:get_snapshot
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\spot\market.py:62:depth
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:67:query
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:116:send_request
C:\Users\Artyt\anaconda3\envs\testEnv\lib\site-packages\binance\api.py:169:_handle_exception
]. Retrying: 1
INFO:root:Start to connect....
INFO:root:Server connected

From your error message, it looks like you did not set symbol in the python script. Please set the appropriate symbol and try agin.

@RT-Tap
Copy link

RT-Tap commented Jul 19, 2021

I've tried all sorts of symbols like bnbusdt, btcusdt, ethusdt, btceth, ethbtc ... all return this error. I know the script makes everything lowercase but I've run out of things to try so I started trying the symbols in uppercase just as a swing in the dark. Is there a special format for the symbol? Also I feel like my output is really long is that ok? Or should I cut it out or replace it with a link?

At this point I've tried on windows, WSL, Arch linux (on a spare machine AND VM), and about to try on debian, windows gives the SSL error or the one I posted above. Sometimes after I set the SSL cert i'll get this other error however I noticed that SSL cert doesn't stay defined and reverts back to default after some time, or the anaconda prompt will say it's defined but when I run conda info -s in a powershell terminal using a virtual environment it reports that no SSL cert is set and I can't get it to set/ report back that it's set.

I just don't know what to try anymore, I've spent way too much time trying to figure this out and I really only need this script to compare to mine and see if mine is working correctly.

EDIT: I got it working, I'm not entirely sure what I managed to do but I have gotten it to finally work, however I do notice why you don't want this to run on Windows, It has the a bug with Async, I've encountered this before, the sccript does not exit cleanly, or rather there is no way to exit the script cleanly because even if you throw a keyboard interrupt the websocket stays open and responds to server pings but doesnt close entirely. This is due to, from what I understand, the exception being thrown during a task but not making it to the scope of the top level handler.
If I may suggest adding the folloing to take car of this :

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        os._exit(0)

@Kenisy
Copy link
Author

Kenisy commented Jul 20, 2021

Normal spot examples run fine but when I run any websocket example I get this error:

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

Could you help me fix this issue ?

This is a known issue with pyOpenSSL package on windows. The bug is that twisted does not includes a trust root sets of its own. The workaround here is by using certifi and setting the correct environment variable for twisted manually. This is the API documentation about the environment variable(SSL_CERT_FILE) to set for twisted.

If you run the file from cmd,

pip install certifi
for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
python example.py

if you run the file on an IDE e.g pycharm,

  1. pip install certifi
  2. Get the directory of cacert.pem file by running python -m certifi
  3. Copy the directory path and set the Environment Variables for SSL_CERT_FILE. These are the steps to setup environment variable on windows.
  4. Restart IDE and run the websocket example

P.S: I did these by using PyCharm and PyCharm imports environment variables automatically when running the project. If you are using other IDEs, please ensure that the project runs with the system's environment variables.

Hi, just wanna confirm that this is the solution and I can run websocket examples normally now. Thanks for your help.

@equj
Copy link

equj commented Dec 18, 2021

The same issue when running on MacOS.
The same solution as suggested above works.
$ python -m certifi
path/to/file/cacert.pem
$ export SSL_CERT_FILE=path/to/file/cacert.pem

@fncondo
Copy link

fncondo commented Dec 20, 2021

Hi,
I experienced the same issues with SSL Error, running Windows 10.
The FIX was:

  1. Run the following lines of code in cmd:
    pip install certifi
    for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
  2. Add new System Variable within Windows here
    name=SSL_CERT_FILE, and path= the directory to cacert.pem file you just set.

@umutgur
Copy link

umutgur commented Mar 7, 2022

The same issue when running on MacOS. The same solution as suggested above works. $ python -m certifi path/to/file/cacert.pem $ export SSL_CERT_FILE=path/to/file/cacert.pem

I tried this on mac, and I saw SSL_CERT_FILE variable on printenv command. But still getting same issue

@miron
Copy link

miron commented Jul 11, 2022

At this point I've tried on windows, WSL, Arch linux (on a spare machine AND VM), and about to try on debian, windows gives the SSL error or the one I posted above. Sometimes after I set the SSL cert i'll get this other error however I noticed that SSL cert doesn't stay defined and reverts back to default after some time, or the anaconda prompt will say it's defined but when I run conda info -s in a powershell terminal using a virtual environment it reports that no SSL cert is set and I can't get it to set/ report back that it's set.

For powershell just run:

PS C:\> $env:SSL_CERT_FILE=(py -m certifi); py yourscript.py

@miron
Copy link

miron commented Jul 11, 2022

I modified the example to set the needed environment variable in the script.
It can also be interrupted with Ctr-C if you have no Break/Pause key (or don't wan't to use Ctrl-Pause or Ctrl-ScrLK on the osk)

import os, certifi, win32api
from binance.websocket.spot.websocket_client \
    import SpotWebsocketClient as WebsocketClient
os.environ['SSL_CERT_FILE'] = certifi.where()
ws_client = WebsocketClient()


def message_handler(message):
    print(message)


ws_client.start()

ws_client.mini_ticker(
    symbol='bnbusdt',
    id=1,
    callback=message_handler,
)

# Combine selected streams
ws_client.instant_subscribe(
    stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'],
    callback=message_handler,
)

win32api.SetConsoleCtrlHandler(lambda _: ws_client.stop(), True)

@chn-lee-yumi
Copy link

chn-lee-yumi commented Feb 4, 2023

I met SSL error: unregistered scheme (in ) and I found the answer from here: https://dev.binance.vision/t/somebody-help-connection-never-succeeded/10663

Just run $env:SSL_CERT_FILE=(py -m certifi) and then run the python script in PowerShell.

@mirandole
Copy link

mirandole commented May 5, 2023

$env:SSL_CERT_FILE=(py -m certifi); py yourscript.py

This answer resolved the issue on my windows 10 computer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewing reviewing the issue
Projects
None yet
Development

No branches or pull requests