Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,13 +86,31 @@ async def proxy(request: Request):
|
|
| 86 |
try:
|
| 87 |
response_str = bytes(response).decode("utf-8")
|
| 88 |
logger.debug("Decoded response: %s", response_str)
|
| 89 |
-
#
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
logger.warning("Decoding failed: %s", str(e))
|
| 95 |
# Continue reading
|
|
|
|
| 96 |
except Exception as e:
|
| 97 |
logger.error("Error reading response: %s", str(e))
|
| 98 |
break
|
|
|
|
| 86 |
try:
|
| 87 |
response_str = bytes(response).decode("utf-8")
|
| 88 |
logger.debug("Decoded response: %s", response_str)
|
| 89 |
+
# More robust JSON-RPC detection
|
| 90 |
+
# Check if we have a complete JSON object
|
| 91 |
+
if len(response_str.strip()) > 0:
|
| 92 |
+
# Try to parse as JSON
|
| 93 |
+
import json
|
| 94 |
+
try:
|
| 95 |
+
json_data = json.loads(response_str)
|
| 96 |
+
# Check if it's a valid JSON-RPC response
|
| 97 |
+
if isinstance(json_data, dict) and "jsonrpc" in json_data:
|
| 98 |
+
# Check if it's a response (has id or error)
|
| 99 |
+
if "id" in json_data or "error" in json_data:
|
| 100 |
+
logger.info("Complete JSON-RPC response detected")
|
| 101 |
+
break
|
| 102 |
+
except json.JSONDecodeError as e:
|
| 103 |
+
# If JSON parsing fails, continue reading
|
| 104 |
+
logger.debug("JSON parsing failed: %s", str(e))
|
| 105 |
+
# Continue reading
|
| 106 |
+
continue
|
| 107 |
+
else:
|
| 108 |
+
# Empty response, continue reading
|
| 109 |
+
continue
|
| 110 |
except Exception as e:
|
| 111 |
logger.warning("Decoding failed: %s", str(e))
|
| 112 |
# Continue reading
|
| 113 |
+
continue
|
| 114 |
except Exception as e:
|
| 115 |
logger.error("Error reading response: %s", str(e))
|
| 116 |
break
|