sumple_ws.py
from websocket import create_connection
↓
Traceback (most recent call last):
File "sumple_ws.py", line 10, in <module>
from websocket import create_connection
ImportError: cannot import name 'create_connection' from 'websocket' (unknown location)
:thinking:
Es scheint, dass die auf der Server- und der Client-Seite zu verwendenden Pakete unterschiedlich sind
In diesem Fall falsch
$ pip install websocket
Dies ist die richtige Antwort
$ pip install websocket-client
Beim Importieren handelt es sich jedoch beide um "Websocket" Bitte lesen Sie den lesbaren Code
Ja super
$ pip install websocket-client
$ pip uninstall websocket
$ pip freeze | grep websocket
websocket-client==0.57.0
Wird reproduziert
sumple_ws.py
from websocket import create_connection
Traceback (most recent call last):
File "sumple_ws.py", line 10, in <module>
from websocket import create_connection
ImportError: cannot import name 'create_connection' from 'websocket' (unknown location)
Überprüfen Sie im interaktiven Modus
>>> import websocket
>>> dir(websocket)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
:thinking: :thinking: :thinking:
$ pip uninstall websocket-client
$ pip install websocket-client
Interaktiver Modus
```python
>>> import websocket
>>> dir(websocket)
['ABNF', 'DEFAULT_SOCKET_OPTION', 'STATUS_ABNORMAL_CLOSED', 'STATUS_BAD_GATEWAY', 'STATUS_GOING_AWAY', 'STATUS_INVALID_EXTENSION', 'STATUS_INVALID_PAYLOAD', 'STATUS_MESSAGE_TOO_BIG', 'STATUS_NORMAL', 'STATUS_POLICY_VIOLATION', 'STATUS_PROTOCOL_ERROR', 'STATUS_STATUS_NOT_AVAILABLE', 'STATUS_TLS_HANDSHAKE_ERROR', 'STATUS_UNEXPECTED_CONDITION', 'STATUS_UNSUPPORTED_DATA_TYPE', 'WebSocket', 'WebSocketAddressException', 'WebSocketApp', 'WebSocketBadStatusException', 'WebSocketConnectionClosedException', 'WebSocketException', 'WebSocketPayloadException', 'WebSocketProtocolException', 'WebSocketProxyException', 'WebSocketTimeoutException', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_abnf', '_app', '_cookiejar', '_core', '_exceptions', '_handshake', '_http', '_logging', '_socket', '_ssl_compat', '_url', '_utils', 'continuous_frame', 'create_connection', 'debug', 'dump', 'enableTrace', 'error', 'frame_buffer', 'getdefaulttimeout', 'isEnabledForDebug', 'isEnabledForError', 'isEnabledForTrace', 'recv', 'recv_line', 'send', 'setdefaulttimeout', 'sock_opt', 'trace', 'warning']
Diesmal perfekt
###Faktor Es scheint, dass aufgrund des Zeitpunkts der Installation und Deinstallation etwas nicht stimmte
Das ist
$ pip install websocket-client
$ pip uninstall websocket
Ich hätte in dieser Reihenfolge sein sollen
$ pip uninstall websocket
$ pip install websocket-client