Re: Cheerypy and ws4py, hearder 'upgrade' is not defined

David Bolen <[email protected]>
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
Vincent Le Goff
<[email protected]> writes:

> When running the script, no error occurs.  But when my browser attempts to
> connect to http://127.0.0.1:9000, a 500 error is displayed.  The log in the
> console displays a full tracebck which ends with:
>
> ws4py.exc.HandshakeError: Header Upgrade is not defined
>
> I remember running into this error previously, but I can't remember in what
> circumstances.  I'm not running behind a proxy.  Is it an error in my
> configuration?

When you connect to http://127.0.0.1:9000, that's not a WebSocket
connection request, so will not include the Upgrade header.  If you have
that endpoint defined for WebSockets (by using the tool in ws4py) it'll
fail with that error when it can't find the header.

In just a quick glance through your code, it appears that you've marked
your root (/) endpoint as a WebSocket (wrapped it in the ws4py tool),
yet are trying to return plain HTML?

I'm sure with some appropriate logic within the request handler you
could support both HTML and WebSocket on the same endpoint, but probably
not with the default WebSocketTool from ws4py.  Instead you'd have to
check the request headers first, to decide whether or not to upgrade the
connection.

If it were me, I'd just separate the two purposes, say by using /ws for
your WebSocket connections for example, leaving / for regular HTML.

-- David

-- 
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.