Code:
import websocket
ws = websocket.WebSocket()
ws.connect('wss://stream2.binance.com:9443/ws/!miniTicker@arr@3000ms')
record = ws.recv()
print(record)
I was trying to get realtime data from Binance Websocket API. while trying to fetch data with this sample url
wss://stream.binance.com:9443/ws/bnbbtc@depth
I am getting this error which says the SSL Verification is failed.
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
Traceback : pastebin.com/RiHn025Z
What I've already tried:
So I found this question on SO How to create Python secure websocket client request? and followed the steps with this code
ws = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE})
ws.connect("wss://stream2.binance.com:9443/ws/!miniTicker@arr@3000ms")
But then a NameError occured:
NameError: name 'ssl' is not defined
I tried to add an Exception (which is ridiculous but still...) which resulted in SyntaxError.
Other Scopes
I tried with different websocket API which uses wss:// but worked just fine in the first code itself.
wss://ws.blockchain.info/inv
{"op":"ping"}
Conditions:
I tried an Echo Test on websockets.org and the wss url is fully functional.
Any help will be appreciated. there are other modules available specifically for binance but I'd like to have the raw data so I am using this api.
Thanks for reading my Question.
GitHub URL for websocket-client : https://github.com/websocket-client/websocket-client
TypeError: __init__() takes exactly 4 arguments (1 given)
for theWebSocket
initializer. What version of websocket are you using? Does your example actually run for you? – Sabinasabine