Websockets problem

24 views
Skip to first unread message

Vlad Leberstein

unread,
Aug 13, 2014, 1:07:00 PM8/13/14
to circuit...@googlegroups.com
Hi! I'm trying to run circuits/examples/web/websockets.py from bitbucket repos default branch on python 3.4 but it fails with the following error:

Traceback (most recent call last):
  File "websockets.py", line 5, in <module>
    from circuits.web.dispatchers import WebSockets
ImportError: cannot import name 'WebSockets'

According to circuits/web/dispatchers/__init__.py, circuits/web/websockets/__init__.py and circuits/web/websockets/dispatcher.py there is nothing called "WebSockets". I replaced "WebSockets" with "WebSocketsDispatcher"(which is intended one I believe) and the example starts but doesn't work as expected: read event handler is never called on "Echo" component and "ws.onclose" callback on client(Firefox browser) is fired right after "new WebSocket("ws://localhost:8000/websocket");" call. Am I doing something wrong or the example(or websockets component) is broken? Thanks in advance!

James Mills

unread,
Aug 13, 2014, 5:08:58 PM8/13/14
to circuit...@googlegroups.com
Actually. If you and I could work together to fix websockets
in circuits.web that would be awesome. Right now the unit tests
fail on Drone.io but pass locally, the example is broken and
I don't know of anyone using it in practise right now.

I think the API could do with a bit of an overhaul so it's a bit
simpler to import and use.

Thoughts?

cheers
James

--
You received this message because you are subscribed to the Google Groups "circuits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to circuits-user...@googlegroups.com.
To post to this group, send email to circuit...@googlegroups.com.
Visit this group at http://groups.google.com/group/circuits-users.
For more options, visit https://groups.google.com/d/optout.

James Mills

unread,
Aug 13, 2014, 8:07:44 PM8/13/14
to circuit...@googlegroups.com
Actually I just realized that I have a project
I'm working on for my PhD that uses websockets
and the websockets stuff in circuits.web works just fine.

I'll update the example so it's in working order.

cheers
James

Vlad Leberstein

unread,
Aug 15, 2014, 8:22:56 PM8/15/14
to circuit...@googlegroups.com
Nice to hear that it's not broken! Looking forward to see an updated expample - I still can't get it working :(

Vlad Leberstein

unread,
Aug 15, 2014, 11:04:32 PM8/15/14
to circuit...@googlegroups.com
I've investigated a bit and found out that the problem is caused by "Sec-Websocket-Accept" header value in HTTP "Switching Protocols" message not being decoded to unicode and python casts bytearray to string like b'<str>'. So if
"accept" bytearray in WebSocketsDispatcher._on_request is decoded to unicode(i.e. response.headers["Sec-WebSocket-Accept"] = accept.decode() ) everyting works just fine.
Bug occurs on python 3.4 win7. Can't test other configurations now - maybe tomorrow.


On Thursday, August 14, 2014 4:07:44 AM UTC+4, James Mills wrote:

James Mills

unread,
Aug 16, 2014, 8:29:31 AM8/16/14
to circuit...@googlegroups.com

On Sat, Aug 16, 2014 at 1:04 PM, Vlad Leberstein <zeroni...@gmail.com> wrote:
I've investigated a bit and found out that the problem is caused by "Sec-Websocket-Accept" header value in HTTP "Switching Protocols" message not being decoded to unicode and python casts bytearray to string like b'<str>'. So if
"accept" bytearray in WebSocketsDispatcher._on_request is decoded to unicode(i.e. response.headers["Sec-WebSocket-Accept"] = accept.decode() ) everyting works just fine.
Bug occurs on python 3.4 win7. Can't test other configurations now - maybe tomorrow.

Hmm makes sense to me. Submit a PR for this! Please :)
Reply all
Reply to author
Forward
0 new messages