-
Notifications
You must be signed in to change notification settings - Fork 515
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
Comments
thanks for your feedback, please share a few info:
|
My python version is 3.7.10 |
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:
It seems to be failing on the SSL certificate verification. Update: I'm running Python 3.8.3 on Windows 10. |
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 :)) |
Get the key from https://testnet.binancefuture.com/cn/futures/BTCUSDT , still cant get the listenkey via client.new_listen_key() |
This library is not support futures yet, so the futures testnet api key will not working here. |
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,
if you run the file on an IDE e.g pycharm,
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. |
What about production futures? Can i have my real api key working here? |
Futures (testnet and production) is not supported by this library. |
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.
And the output/result of trying what is mentioned in the above post I get:
|
From your error message, it looks like you did not set |
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 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.
|
Hi, just wanna confirm that this is the solution and I can run websocket examples normally now. Thanks for your help. |
The same issue when running on MacOS. |
Hi,
|
I tried this on mac, and I saw SSL_CERT_FILE variable on |
For powershell just run: PS C:\> $env:SSL_CERT_FILE=(py -m certifi); py yourscript.py |
I modified the example to set the needed environment variable in the script. 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) |
I met Just run |
This answer resolved the issue on my windows 10 computer. |
Normal spot examples run fine but when I run any websocket example I get this error:
Could you help me fix this issue ?
The text was updated successfully, but these errors were encountered: