Python websocket - error: NameError("name 'opcode' is not defined",)
Hi,
I am trying to create a function in Python call API authorize function and seems always give me the same error:
NameError("name 'opcode' is not defined",)
Am I missing some setting???
Code as below, any idea???
import websocket
import json
def on_message(ws, message):
print('authorise: %s' % message)
def on_open(ws):
json_data = json.dumps({'authorize':'XXXXXXXXX'})
ws.send(json_data)
def on_error(ws, error):
print('authorise: %s' % error)
def toAuthorise ():
apiUrl = "wss://ws.binaryws.com/websockets/v3"
ws = websocket.WebSocketApp(apiUrl, on_message = on_message, on_open = on_open, on_error = on_error)
ws.run_forever()
Comments
Can you try code sample from https://developers.binary.com/demos/
Raunak,
I did try out exactly from the code sample, and it give me the same error.
May I know which version of Python you are using? We recommend using Python 2 as of now. Also, for the websocket library, you will need to install the right one via 'pip install websocket-client'
teo,
I am using Python 3.4 and install with websocket-client==0.39.0
teo,
I try on python 2.7 and it works! Thanks.
All good now.