websockets icon indicating copy to clipboard operation
websockets copied to clipboard

path not subscriptable

Open Miolus opened this issue 5 years ago • 3 comments

Hi. The path variable in the handler function of a ws-server is not subscriptable, you can't convert it to a string which makes using the path variable a little bit difficult. I suggest the possibility to convert the path to str.

Miolus avatar Jan 19 '21 07:01 Miolus

Could you say what version of Python you're using?

aaugustin avatar Jan 19 '21 08:01 aaugustin

I'm using python 3.8.2

Miolus avatar Jan 19 '21 08:01 Miolus

I cannot reproduce this issue with the information you provided. print(type(path)) at the beginning of a handler prints <class 'str'>. This is a string.

Try it for yourself with this diff:

diff --git a/example/server.py b/example/server.py
index c8ab699..444f6c9 100755
--- a/example/server.py
+++ b/example/server.py
@@ -6,6 +6,7 @@ import asyncio
 import websockets

 async def hello(websocket, path):
+    print(type(path))
     name = await websocket.recv()
     print(f"< {name}")

aaugustin avatar Jan 20 '21 19:01 aaugustin