Repository: ethereum/web3.py

Issue:
 cannot import name 'DEFAULT_WEBSOCKET_TIMEOUT'

ImportError: cannot import name 'DEFAULT_WEBSOCKET_TIMEOUT' from 'web3.providers.websocket' (C:\Python310\lib\site-packages\web3\providers\websocket\__init__.py)

any one know what happened?


Discussion:

Resolving patch:
diff --git a/web3/manager.py b/web3/manager.py
--- a/web3/manager.py
+++ b/web3/manager.py
@@ -312,38 +312,40 @@ async def _ws_recv_stream(self) -> AsyncGenerator[RPCResponse, None]:
             self.logger.debug("No cache key found for response, returning raw response")
             yield response
 
-        if request_info.method == "eth_subscribe" and "result" in response.keys():
-            # if response for the initial eth_subscribe request, which returns the
-            # subscription id
-            subscription_id = response["result"]
-            cache_key = generate_cache_key(subscription_id)
-            if cache_key not in self._provider._async_response_processing_cache:
-                # cache by subscription id in order to process each response for the
-                # subscription as it comes in
-                self._provider.logger.debug(
-                    f"Caching eth_subscription info:\n    cache_key={cache_key},\n    "
-                    f"request_info={request_info.__dict__}"
-                )
-                self._provider._async_response_processing_cache.cache(
-                    cache_key, request_info
-                )
-
-        # pipe response back through middleware response processors
-        if len(request_info.middleware_response_processors) > 0:
-            response = pipe(response, *request_info.middleware_response_processors)
-
-        (
-            result_formatters,
-            error_formatters,
-            null_formatters,
-        ) = request_info.response_formatters
-        partly_formatted_response = self.formatted_response(
-            response,
-            request_info.params,
-            error_formatters,
-            null_formatters,
-        )
-        yield apply_result_formatters(result_formatters, partly_formatted_response)
+        else:
+            if request_info.method == "eth_subscribe" and "result" in response.keys():
+                # if response for the initial eth_subscribe request, which returns the
+                # subscription id
+                subscription_id = response["result"]
+                cache_key = generate_cache_key(subscription_id)
+                if cache_key not in self._provider._async_response_processing_cache:
+                    # cache by subscription id in order to process each response for the
+                    # subscription as it comes in
+                    self._provider.logger.debug(
+                        f"Caching eth_subscription info:\n    "
+                        f"cache_key={cache_key},\n    "
+                        f"request_info={request_info.__dict__}"
+                    )
+                    self._provider._async_response_processing_cache.cache(
+                        cache_key, request_info
+                    )
+
+            # pipe response back through middleware response processors
+            if len(request_info.middleware_response_processors) > 0:
+                response = pipe(response, *request_info.middleware_response_processors)
+
+            (
+                result_formatters,
+                error_formatters,
+                null_formatters,
+            ) = request_info.response_formatters
+            partly_formatted_response = self.formatted_response(
+                response,
+                request_info.params,
+                error_formatters,
+                null_formatters,
+            )
+            yield apply_result_formatters(result_formatters, partly_formatted_response)
 
 
 class _AsyncPersistentRecvStream:
diff --git a/web3/providers/websocket/__init__.py b/web3/providers/websocket/__init__.py
--- a/web3/providers/websocket/__init__.py
+++ b/web3/providers/websocket/__init__.py
@@ -1,4 +1,6 @@
 from .websocket import (  # noqa: F401
+    DEFAULT_WEBSOCKET_TIMEOUT,
+    RESTRICTED_WEBSOCKET_KWARGS,
     WebsocketProvider,
 )
 from .websocket_v2 import (  # noqa: F401


Test patch: