I am using Python 3.4 and websocket-client 0.44. I am trying a Python webscoket script to fetch stream data from Bitfinex using socket. Here is my script which which i have written:
import json
from websocket import create_connection
ws = create_connection("wss://api.bitfinex.com/ws/2")
#ws.connect("wss://api2.bitfinex.com:3000/ws")
ws.send(json.dumps({
"event": "subscribe",
"channel": "book",
"symbol": "tBTCUSD",
}))
while True:
result = ws.recv()
result = json.loads(result)
xxx = result
print(xxx)
#print(result[1])
ws.close()
and what i am getting is, error:
Traceback (most recent call last):
File "D:/bitstamp/socket.py", line 3, in <module>
from websocket import create_connection
File "C:\Python34\lib\site-packages\websocket_client-0.44.0-py3.4.egg\websocket\__init__.py", line 23, in <module>
from ._app import WebSocketApp
File "C:\Python34\lib\site-packages\websocket_client-0.44.0-py3.4.egg\websocket\_app.py", line 35, in <module>
from ._core import WebSocket, getdefaulttimeout
File "C:\Python34\lib\site-packages\websocket_client-0.44.0-py3.4.egg\websocket\_core.py", line 24, in <module>
import socket
File "D:\bitstamp\socket.py", line 3, in <module>
from websocket import create_connection
ImportError: cannot import name 'create_connection'
Is there an issue in Python 3.4 or am I doing this incorrectly?
There is nothing wrong with Python 3.4. It seems you may be missing the websocket-client package.
Please install this package by running the command in your terminal as shown below and that should solve your issue.
pip install websocket-client
Don't call your script socket.py
. There is already a socket
in Python's standard library, and you are conflicting with it. You can tell that this is the problem by following the traceback: It starts in your script, descends into websocket
, eventually tries to import socket
, and gets your script again.
you should first install websocket-client, or install websocket-client after uninstalling websocket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With