diff --git a/README.md b/README.md index cea6f07..8a8ce1b 100644 --- a/README.md +++ b/README.md @@ -107,44 +107,3 @@ To get the correct SSID: 5. Look for a message that starts with `42["auth",` 6. Copy the **entire message** including the `42["auth",{...}]` part -### Websockets version error - -## Traceback: -``` -2025-07-13 15:25:16.531 | INFO | pocketoptionapi_async.client:__init__:130 - Initialized PocketOption client (demo=True, uid=105754921, persistent=False) with enhanced monitoring -2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:connect:162 - Connecting to PocketOption... -2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:187 - Starting regular connection... -2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:198 - Demo mode: Using demo regions: ['DEMO', 'DEMO_2'] -2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:219 - Trying region: DEMO with URL: wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket -2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.websocket_client:connect:162 - Attempting to connect to wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket -2025-07-13 15:25:16.556 | WARNING | pocketoptionapi_async.websocket_client:connect:206 - Failed to connect to wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers' -2025-07-13 15:25:16.556 | WARNING | pocketoptionapi_async.client:_start_regular_connection:242 - Failed to connect to region DEMO: Failed to connect to any WebSocket endpoint -2025-07-13 15:25:16.556 | INFO | pocketoptionapi_async.client:_start_regular_connection:219 - Trying region: DEMO_2 with URL: wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket -2025-07-13 15:25:16.556 | INFO | pocketoptionapi_async.websocket_client:connect:162 - Attempting to connect to wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket -2025-07-13 15:25:16.558 | WARNING | pocketoptionapi_async.websocket_client:connect:206 - Failed to connect to wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers' -2025-07-13 15:25:16.558 | WARNING | pocketoptionapi_async.client:_start_regular_connection:242 - Failed to connect to region DEMO_2: Failed to connect to any WebSocket endpoint -Traceback (most recent call last): - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/test1.py", line 20, in - asyncio.run(main()) - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/runners.py", line 190, in run - return runner.run(main) - ^^^^^^^^^^^^^^^^ - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/runners.py", line 118, in run - return self._loop.run_until_complete(task) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete - return future.result() - ^^^^^^^^^^^^^^^ - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/test1.py", line 9, in main - account_info = await client.get_balance() - ^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/site-packages/pocketoptionapi_async/client.py", line 376, in get_balance - raise ConnectionError("Not connected to PocketOption") -pocketoptionapi_async.exceptions.ConnectionError: Not connected to PocketOption -``` - -to fix this error, run this commands: -``` -pip uninstall websockets -pip install websockets==11.0 -``` diff --git a/docs/termux-setup.html b/docs/termux-setup.html index 1807b3a..21d02ec 100644 --- a/docs/termux-setup.html +++ b/docs/termux-setup.html @@ -84,13 +84,8 @@

7. Run Your First Script

If everything is configured correctly, you should see your account balance displayed.

-
+

Common Issues and Solutions

-

WebSocket Connection Error

-

If you encounter a WebSocket connection error with extra_headers, fix it by:

-
pip uninstall websockets
-pip install websockets==11.0
-

Permission Denied Errors

If you get permission errors when installing packages:

termux-setup-storage
diff --git a/pocketoptionapi_async/__init__.py b/pocketoptionapi_async/__init__.py index bc3e914..dc9c7b3 100644 --- a/pocketoptionapi_async/__init__.py +++ b/pocketoptionapi_async/__init__.py @@ -40,7 +40,7 @@ # Create REGIONS instance REGIONS = Regions() -__version__ = "2.0.0" +__version__ = "2.0.1" __author__ = "PocketOptionAPI Team" __all__ = [ diff --git a/pocketoptionapi_async/connection_keep_alive.py b/pocketoptionapi_async/connection_keep_alive.py index 23d4b00..b795a4f 100644 --- a/pocketoptionapi_async/connection_keep_alive.py +++ b/pocketoptionapi_async/connection_keep_alive.py @@ -6,8 +6,9 @@ from typing import Optional, List, Callable, Dict, Any from datetime import datetime, timedelta from loguru import logger + +import websockets.legacy.client from websockets.exceptions import ConnectionClosed -from websockets.legacy.client import connect, WebSocketClientProtocol from models import ConnectionInfo, ConnectionStatus from constants import REGIONS @@ -23,7 +24,7 @@ def __init__(self, ssid: str, is_demo: bool = True): self.is_demo = is_demo # Connection state - self.websocket: Optional[WebSocketClientProtocol] = None + self.websocket: Optional[websockets.legacy.client.WebSocketClientProtocol] = None self.connection_info: Optional[ConnectionInfo] = None self.is_connected = False self.should_reconnect = True @@ -138,7 +139,7 @@ async def _establish_connection(self) -> bool: # Connect with headers (like old API) self.websocket = await asyncio.wait_for( - connect( + websockets.legacy.client.connect( url, ssl=ssl_context, extra_headers={ diff --git a/pocketoptionapi_async/websocket_client.py b/pocketoptionapi_async/websocket_client.py index c3c93ff..752ee21 100644 --- a/pocketoptionapi_async/websocket_client.py +++ b/pocketoptionapi_async/websocket_client.py @@ -10,9 +10,10 @@ from typing import Optional, Callable, Dict, Any, List, Deque from datetime import datetime from collections import deque -import websockets + +import websockets.legacy.client from websockets.exceptions import ConnectionClosed -from websockets.legacy.client import WebSocketClientProtocol + from loguru import logger from .models import ConnectionInfo, ConnectionStatus, ServerTime @@ -63,7 +64,7 @@ class ConnectionPool: """Connection pool for better resource management""" def __init__(self, max_connections: int = 3): - self.active_connections: Dict[str, WebSocketClientProtocol] = {} + self.active_connections: Dict[str, websockets.legacy.client.WebSocketClientProtocol] = {} self.connection_stats: Dict[str, Dict[str, Any]] = {} self._pool_lock = asyncio.Lock() @@ -120,7 +121,7 @@ class AsyncWebSocketClient: """ def __init__(self): - self.websocket: Optional[WebSocketClientProtocol] = None + self.websocket: Optional[websockets.legacy.client.WebSocketClientProtocol] = None self.connection_info: Optional[ConnectionInfo] = None self.server_time: Optional[ServerTime] = None self._ping_task: Optional[asyncio.Task] = None @@ -169,7 +170,7 @@ async def connect(self, urls: List[str], ssid: str) -> bool: # Connect with timeout ws = await asyncio.wait_for( - websockets.connect( + websockets.legacy.client.connect( url, ssl=ssl_context, extra_headers=DEFAULT_HEADERS, diff --git a/pyproject.toml b/pyproject.toml index eadb0da..ac3cd8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ ] dependencies = [ "aiohttp>=3.8.0", - "websockets>=11.0.0", + "websockets>=12.0", "asyncio", "python-dotenv>=1.0.0", "tzlocal>=4.0.0", diff --git a/requirements.txt b/requirements.txt index c5bbe02..500715a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohttp>=3.8.0 -websockets>=11.0.0 +websockets>=12.0 asyncio python-dotenv>=1.0.0 tzlocal>=4.0.0 diff --git a/tools/client_test.py b/tools/client_test.py index 39ff86a..a50bb9f 100644 --- a/tools/client_test.py +++ b/tools/client_test.py @@ -1,5 +1,5 @@ -import websockets import anyio +import websockets.legacy.client from rich.pretty import pprint as print from pocketoptionapi_async.constants import REGIONS @@ -12,7 +12,7 @@ async def websocket_client(url, pro): for i in region_urls: print(f"Trying {i}...") try: - async with websockets.connect( + async with websockets.legacy.client.connect( i, extra_headers={ "Origin": "https://pocketoption.com/" # main URL