{"id":7862,"library":"websocket","title":"Websocket (gevent)","description":"The `websocket` library, version 0.2.1, released in 2011, provides a WebSocket client implementation specifically for use with the `gevent` asynchronous framework. This project is no longer actively maintained and is considered abandoned, making it unsuitable for modern Python development. Developers should use `websocket-client` for synchronous applications or `websockets` for asyncio-based applications instead.","status":"abandoned","version":"0.2.1","language":"en","source_language":"en","source_url":"https://github.com/aaugustin/python-websocket","tags":["websocket","gevent","networking","abandoned"],"install":[{"cmd":"pip install websocket","lang":"bash","label":"Install websocket 0.2.1"},{"cmd":"pip install websocket-client","lang":"bash","label":"Install modern alternative: websocket-client"},{"cmd":"pip install websockets","lang":"bash","label":"Install modern alternative: websockets (asyncio)"}],"dependencies":[{"reason":"This library is designed as a WebSocket implementation specifically for the gevent asynchronous framework.","package":"gevent","optional":false}],"imports":[{"note":"Used for establishing a WebSocket client connection in this older library.","symbol":"create_connection","correct":"from websocket import create_connection"},{"note":"Commonly confused with `websocket-client`'s primary class for client connections. The old `websocket` library also has a `WebSocket` class, but `create_connection` is the recommended entry point for client usage.","wrong":"from websocket_client import WebSocket","symbol":"WebSocket","correct":"from websocket import WebSocket"}],"quickstart":{"code":"import os\nimport gevent\nfrom gevent import monkey; monkey.patch_all()\nfrom websocket import create_connection\n\ntry:\n    # Note: Many modern servers may not support the old protocol handshake\n    # This example connects to a public echo server that might be lenient.\n    ws_url = os.environ.get('WEBSOCKET_URL', 'ws://echo.websocket.events/')\n    print(f\"Connecting to {ws_url} with gevent-based websocket...\")\n    ws = create_connection(ws_url)\n    print(\"Sending 'Hello, World!'...\")\n    ws.send(\"Hello, World!\")\n    print(\"Receiving...\")\n    result = ws.recv()\n    print(f\"Received: '{result}'\")\n    ws.close()\n    print(\"Connection closed.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"This library is very old and may not be compatible with modern WebSocket servers or Python environments.\")\n    print(\"Consider using 'websocket-client' or 'websockets' instead.\")","lang":"python","description":"This quickstart demonstrates a basic WebSocket client connection using the `websocket` library, patching `gevent` for its asynchronous operations. It attempts to connect to a public echo server and send/receive a message. Due to the library's age, compatibility with modern WebSocket servers is not guaranteed. Ensure `gevent` is installed alongside `websocket` for this to run."},"warnings":[{"fix":"Migrate to `websocket-client` (synchronous) or `websockets` (asyncio) for current Python projects.","message":"This library is fundamentally incompatible with modern WebSocket protocol versions and Python standards. Its last release was in 2011, predating significant advancements and RFC finalizations (e.g., RFC 6455). Using it will likely result in connection failures or unexpected behavior with contemporary WebSocket servers.","severity":"breaking","affected_versions":"0.2.1 and earlier"},{"fix":"Always use `pip install websocket-client` for the modern synchronous client or `pip install websockets` for the asyncio client. Verify your `requirements.txt` and import statements.","message":"The `websocket` package (0.2.1, gevent-based) is a distinct, abandoned library, often confused with the actively maintained `websocket-client` package. Importing `websocket` will install the old version, not the modern client.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to a modern WebSocket library like `websocket-client` or `websockets` that fully implements RFC 6455 and newer extensions.","message":"The library relies on a very old version of the WebSocket protocol (likely HyBi-00 to HyBi-07, pre-RFC 6455), which is not fully supported or implemented by most modern WebSocket servers. Connections will often fail during the handshake or exhibit unexpected frame handling.","severity":"deprecated","affected_versions":"0.2.1 and earlier"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"You have installed the wrong package. Uninstall `websocket` and install the correct, actively maintained library: `pip uninstall websocket && pip install websocket-client`.","cause":"Attempting to use features from `websocket-client` (like `WebSocketApp`) after installing the old `websocket` package.","error":"ImportError: cannot import name 'WebSocketApp' from 'websocket'"},{"fix":"Ensure `gevent.monkey.patch_all()` is called early in your script if you absolutely must use this library. More importantly, migrate to a modern WebSocket client library like `websocket-client` or `websockets` to ensure compatibility with contemporary servers.","cause":"This generic socket error, when encountered with `websocket` 0.2.1, frequently indicates that the target WebSocket server actively rejected the connection due to an outdated protocol handshake or unsupported features, or a missing `gevent.monkey.patch_all()` call if gevent isn't properly initialized.","error":"socket.error: [Errno 10061] No connection could be made because the target machine actively refused it"}]}