gpt4 book ai didi

python-3.x - 导入错误: cannot import name 'create_connection'

转载 作者:行者123 更新时间:2023-12-01 16:25:43 26 4
gpt4 key购买 nike

我正在使用 Python 3.4 和 websocket-client 0.44。我正在尝试使用 Python webscoket 脚本从 Bitfinex 获取流数据使用套接字。这是我编写的脚本:

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()

我得到的是错误:

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'

Python 3.4 中是否存在问题或者我这样做不正确?

最佳答案

Python 3.4 没有任何问题。看来您可能缺少 websocket-client 包。

请通过在终端中运行命令来安装此软件包,如下所示,这应该可以解决您的问题。

pip install websocket-client

关于python-3.x - 导入错误: cannot import name 'create_connection' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47344216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com