Bug: hello can't connect with ws in python and surrealdb:nightly
Closed this issue · 5 comments
Describe the bug
try to connect :
async with Surreal("ws://surrealdb:8000/rpc") as db:
await db.signin({"user": "root", "pass": "root"})
await db.use("test", "test")
get error
ERROR: Exception in ASGI application
devfram-fastapi-1 | Traceback (most recent call last):
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
devfram-fastapi-1 | result = await app( # type: ignore[func-returns-value]
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
devfram-fastapi-1 | return await self.app(scope, receive, send)
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 289, in call
devfram-fastapi-1 | await super().call(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 122, in call
devfram-fastapi-1 | await self.middleware_stack(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in call
devfram-fastapi-1 | raise exc
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in call
devfram-fastapi-1 | await self.app(scope, receive, _send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 83, in call
devfram-fastapi-1 | await self.app(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in call
devfram-fastapi-1 | raise exc
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in call
devfram-fastapi-1 | await self.app(scope, receive, sender)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in call
devfram-fastapi-1 | raise e
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in call
devfram-fastapi-1 | await self.app(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 718, in call
devfram-fastapi-1 | await route.handle(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
devfram-fastapi-1 | await self.app(scope, receive, send)
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
devfram-fastapi-1 | response = await func(request)
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 273, in app
devfram-fastapi-1 | raw_response = await run_endpoint_function(
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 190, in run_endpoint_function
devfram-fastapi-1 | return await dependant.call(**values)
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/app/main.py", line 208, in testdb
devfram-fastapi-1 | await db.signin({"user": "root", "pass": "root"})
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 282, in signin
devfram-fastapi-1 | response = await self._send_receive(
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 683, in _send_receive
devfram-fastapi-1 | return await self._recv()
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 711, in _recv
devfram-fastapi-1 | return ResponseSuccess(**response)
devfram-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
devfram-fastapi-1 | File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init
devfram-fastapi-1 | pydantic.error_wrappers.ValidationError: 1 validation error for ResponseSuccess
devfram-fastapi-1 | id
devfram-fastapi-1 | str type expected (type=type_error.str)
Steps to reproduce
try to connect
Expected behaviour
connect
SurrealDB version
nightly
surrealdb.py version
last main
Contact Details
No response
Is there an existing issue for this?
- I have searched the existing issues
Code of Conduct
- I agree to follow this project's Code of Conduct
It seems like you've entered the wrong command, should be Surreal("ws://localhost:8000/rpc")
instead of Surreal("ws://surrealdb:8000/rpc")
if you're just doing things locally. if you are making a remote connection, you need you to use the remote a ip.
i use it in docker . docker name is surrealdb .
i can connect thru http but not throu websocket
with insomnia i can connect too.
devfram-fastapi-1 | INFO: Application startup complete.
devfram-surrealdb-1 | 2023-07-13T13:02:29.666448Z INFO surreal::net::log: 172.18.0.5:39980 GET /rpc HTTP/1.1 101 "Python/3.11 websockets/10.4" 72.884µs
devfram-surrealdb-1 | 2023-07-13T13:02:29.666592Z TRACE surreal::net::rpc: WebSocket f8d72fa1-944e-428d-a2d4-d005d75d1216 connected
devfram-surrealdb-1 | 2023-07-13T13:02:29.670148Z TRACE surreal::net::rpc: RPC Received: { id: '9cff43df-a604-490e-951e-35aa66f592b1', method: 'signin', params: [{ pass: 'root', user: 'root' }] }
devfram-surrealdb-1 | 2023-07-13T13:02:29.670219Z TRACE rpc response: surreal::rpc::res: Response sent response=Response { id: Some(Uuid(Uuid(9cff43df-a604-490e-951e-35aa66f592b1))), result: Ok(Other(None)) }
devfram-surrealdb-1 | 2023-07-13T13:02:29.671159Z TRACE surreal::net::rpc: WebSocket f8d72fa1-944e-428d-a2d4-d005d75d1216 disconnected
devfram-surrealdb-1 | 2023-07-13T13:02:34.668419Z TRACE surreal::net::rpc: WebSocket error: ConnectionClosed
devfram-fastapi-1 | 1 validation error for ResponseSuccess
devfram-fastapi-1 | id
devfram-fastapi-1 | str type expected (type=type_error.str)
devfram-fastapi-1 | INFO: 172.18.0.2:35396 - "GET /testdb HTTP/1.1" 200 OK
Hi @coutouly, can you share your code snippet. The problem seems to not come from surrealdb as I tested something similar and it worked without errors.
hello
my docker surrealdb name is surrealdb
from surrealdb import Surreal
from fastapi import FastAPI, Depends, Request
app = FastAPI(root_path="/api/")
@app.get("/test/db")
async def test_db():
async with Surreal("ws://surrealdb:8000/rpc") as db:
await db.signin({"user": "root", "pass": "root"})
await db.use('test', 'test')
await db.create(
"user",
{
"user": "me",
"pass": "safe",
"marketing": True,
"tags": ["python", "documentation"],
},
)
it gave me this error:
archi-surrealdb-1 | 2023-07-20T10:12:59.330343Z INFO surreal::net::log: 172.19.0.6:37404 GET /rpc HTTP/1.1 101 "Python/3.11 websockets/10.4" 43.057µs
archi-surrealdb-1 | 2023-07-20T10:12:59.330468Z TRACE surreal::net::rpc: WebSocket 9d3cfe9f-906f-4499-a0cd-02753e82a6cb connected
archi-surrealdb-1 | 2023-07-20T10:12:59.333938Z TRACE surreal::net::rpc: RPC Received: { id: '11c3e4c0-425e-4199-94c5-8275e827080f', method: 'signin', params: [{ pass: 'root', user: 'root' }] }
archi-surrealdb-1 | 2023-07-20T10:12:59.334032Z TRACE rpc response: surreal::rpc::res: Response sent response=Response { id: Some(Uuid(Uuid(11c3e4c0-425e-4199-94c5-8275e827080f))), result: Ok(Other(None)) }
archi-surrealdb-1 | 2023-07-20T10:12:59.335463Z TRACE surreal::net::rpc: WebSocket 9d3cfe9f-906f-4499-a0cd-02753e82a6cb disconnected
archi-surrealdb-1 | 2023-07-20T10:13:04.331789Z TRACE surreal::net::rpc: WebSocket error: ConnectionClosed
archi-fastapi-1 | INFO: 172.19.0.7:42960 - "GET /test/db HTTP/1.1" 500 Internal Server Error
archi-fastapi-1 | ERROR: Exception in ASGI application
archi-fastapi-1 | Traceback (most recent call last):
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
archi-fastapi-1 | result = await app( # type: ignore[func-returns-value]
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
archi-fastapi-1 | return await self.app(scope, receive, send)
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 289, in __call__
archi-fastapi-1 | await super().__call__(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
archi-fastapi-1 | await self.middleware_stack(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
archi-fastapi-1 | raise exc
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
archi-fastapi-1 | await self.app(scope, receive, _send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 83, in __call__
archi-fastapi-1 | await self.app(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
archi-fastapi-1 | raise exc
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
archi-fastapi-1 | await self.app(scope, receive, sender)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
archi-fastapi-1 | raise e
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
archi-fastapi-1 | await self.app(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 718, in __call__
archi-fastapi-1 | await route.handle(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
archi-fastapi-1 | await self.app(scope, receive, send)
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
archi-fastapi-1 | response = await func(request)
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 273, in app
archi-fastapi-1 | raw_response = await run_endpoint_function(
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 190, in run_endpoint_function
archi-fastapi-1 | return await dependant.call(**values)
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/app/main.py", line 53, in test_db
archi-fastapi-1 | await db.signin({"user": "root", "pass": "root"})
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 282, in signin
archi-fastapi-1 | response = await self._send_receive(
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 683, in _send_receive
archi-fastapi-1 | return await self._recv()
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "/usr/local/lib/python3.11/site-packages/surrealdb/ws.py", line 711, in _recv
archi-fastapi-1 | return ResponseSuccess(**response)
archi-fastapi-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
archi-fastapi-1 | File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
archi-fastapi-1 | pydantic.error_wrappers.ValidationError: 1 validation error for ResponseSuccess
archi-fastapi-1 | id
archi-fastapi-1 | str type expected (type=type_error.str)
it was a problem with my docker
sorry.