I've got a weird error:
$ cat tmp.py
from sanic import Sanic
import websockets
app = Sanic()
@app.websocket("/ws")
async def ws(req, ws):
while True:
data = await ws.recv()
print(data)
await ws.send(data)
app.run(host="localhost", port=8080)
$ python3.6 tmp.py
Traceback (most recent call last):
File "tmp.py", line 6, in <module>
@app.websocket("/ws")
AttributeError: 'Sanic' object has no attribute 'websocket'
I've looked at the doc and in the source code, I don't understand why it doesn't work. I'm using version 0.4.1. Are websockets available on a newer version not yet on PyPi ?
Correct - there is no websocket release yet. Look at the latest tag when browsing.
Or read the stable docs. http://sanic.readthedocs.io/en/stable/
i think the websocket feature will be available at version 0.5.0
https://github.com/channelcat/sanic/milestone/6?closed=1
but you can still use the latest version by installing from github.
pip install git+https://github.com/channelcat/sanic.git
Thanks !
but, of course, you should prefer the stable release I think :smile:
Does anyone happen to know the timeline for 0.5? I've been trying out the websockets in master and it has been excellent so far.
https://github.com/channelcat/sanic/milestone/6
Waiting for #472
oh, thanks - I didn't think to check for milestones. Sorry for the extra noise.
Most helpful comment
https://github.com/channelcat/sanic/milestone/6
Waiting for #472