Safari 5.1.2 not working with pywebsocket (Unexpected response code: 404)

73 views
Skip to first unread message

Barada Sahu

unread,
Dec 14, 2011, 10:04:03 PM12/14/11
to pywebsocket
Hi,

I am trying to create an implementation of Mobile Safari/Safari with
pywebsocket on Apache and currently am stuck with an "Unexpected
response code: 404". Is this because of the Safari websocket protocol
not being compatible with the supported ones by pywebsocket? I see the
documentation on pywebsocket and it does mention that pywebsocket
supports the Safari implementation of the websocket protocol (i.e
Hixie-76)

I see the following request headers from Safari:

Connection:Upgrade
Host:localhost
Origin:http://192.168.1.9
Sec-WebSocket-Key1:rv3322s TJq91 /d 873 0
Sec-WebSocket-Key2:35,990 783 79
Upgrade:WebSocket
(Key3):1D:85:35:B4:B3:C4:2D:C9

Help here would be appreciated.

~ Barada

Takashi Toyoshima

unread,
Dec 14, 2011, 10:48:50 PM12/14/11
to pyweb...@googlegroups.com
Hi,

pywebsocket is compatible with Safari family.
If you get the 404 status, I guess your configuration was wrong.

Please add 'LogLevel debug' setting into your apache configuration,
then check apache's log files.
Yo may want to see example/pywebsocket.conf. It will help you.

Thanks,

--
Takashi Toyoshima
Software Engineer, Google

Barada Sahu

unread,
Dec 14, 2011, 11:22:32 PM12/14/11
to pywebsocket
Hi Takashi,

I have a similar configuration as that in the example/
pywebsocket.conf. (see below). My LogLevel is already set to Debug
(see relevant error message below).
I am able to get the setup working against Chrome and not against
Safari and hence I tend to believe that there may be some issue in
terms of compatibility with Safari.

Apache conf:
LogLevel debug
<IfModule python_module>
PythonPath "sys.path+['/pywebsocket-0.7/src']"
PythonOption mod_pywebsocket.handler_root /pywebsocket-0.7/
src/example
PythonHeaderParserHandler mod_pywebsocket.headerparserhandler
PythonOption mod_pywebsocket.allow_draft75 On
</IfModule>


Apache Logs :
[warn] [client 127.0.0.1] mod_pywebsocket: super() argument 1 must be
type, not classobj

~ Barada

Takashi Toyoshima

unread,
Dec 14, 2011, 11:36:04 PM12/14/11
to pyweb...@googlegroups.com
I tried 0.7 in my environment now.
standalone.py and mod_pywebsocket on Apache seems to work fine to me
with both of Chrome and Safari.

Could you give me more details of your environment?
Server's operating system, Safari version, apache and mod_python version, etc.

I suspect server side python may be incompatible with pywebsocket.
Did you use the same server for both of Chrome and Safari?

Barada Sahu

unread,
Dec 14, 2011, 11:58:34 PM12/14/11
to pywebsocket
Hi Takashi,

I took a look at the logs and this is what I get for Safari.

[Thu Dec 15 09:56:03 2011] [info] mod_pywebsocket.handshake: Trying
IETF HyBi latest protocol
[Thu Dec 15 09:56:03 2011] [warn] [client 127.0.0.1] mod_pywebsocket:


super() argument 1 must be type, not classobj

For Chrome :
[Thu Dec 15 09:57:35 2011] [info] mod_pywebsocket.handshake: Trying
IETF HyBi latest protocol
[Thu Dec 15 09:57:35 2011] [debug] _apachemodule.c(65):
mod_pywebsocket.handshake.hybi.Handshaker: Sec-WebSocket-Key:
'BCQunXGsBH77ulCXpnqkYA==' (04 24 2e 9d 71 ac 04 7e fb ba 50 97 a6 7a
a4 60)

I am using the same server for both Chrome as well as Safari. The
Safari one, must obviously be calling some python function which is
not a part of the Chrome handling because of which I get this error.

Apache 2.2, Python 2.4.4, mod_python-3.3.1

Let me know if you need any further info.

~ Barada

Barada Sahu

unread,
Dec 14, 2011, 11:59:45 PM12/14/11
to pywebsocket
Missed out on Safari version, Safari 5.1.2

Barada Sahu

unread,
Dec 15, 2011, 2:37:17 AM12/15/11
to pywebsocket
Hi Takashi,

Zeroed down on the source of the error which is being caused due to a
missing header in the request : Sec-WebSocket-Version
Is this a mandatory header in the request because Safari 5.1.2 and
Mobile Safari are both not sending this parameter out.

~ Barada

Barada Sahu

unread,
Dec 15, 2011, 5:06:30 AM12/15/11
to pywebsocket
Figured this out. The property below should have the value "on" in
lowercase. The example file has it in CamelCase.
PythonOption mod_pywebsocket.allow_draft75 on

Works now, closing the thread.

~ Barada

Takashi Toyoshima

unread,
Dec 15, 2011, 6:30:33 AM12/15/11
to pyweb...@googlegroups.com
Hi Barada,

Thanks for your investigation.
But, it looks curious.

In my test environment, allow_draft75 value was 'On'.
Actually, we improved its value handling in r570, like
http://code.google.com/p/pywebsocket/source/diff?spec=svn570&r=570&format=side&path=/trunk/src/mod_pywebsocket/headerparserhandler.py
But, the value is evaluated after converting lower case.
So I believe this flag is case insensitive.

In addition, Safari family uses hybi00 protocol, I think.
So, you doesn't need hixie75 flag.

Simply said, protocol version detection works as follows.
1. checks Sec-WebSocket-Version, then goes to 3 if it doesn't exist
2. detects version hybi08 and hybi13, otherwise goes to 3
3. detects version hybi00, otherwise goes to 4
4. handle as hixie75 if allow_draft75 is set

Chrome's version is detected in 2. And Safari will be done in 3.
That's why I think allow_draft75 flag is't related to this issue.

Thanks,

Barada Sahu

unread,
Dec 15, 2011, 7:06:20 AM12/15/11
to pywebsocket
Hi Takashi,

Tried out the various combinations and in all likelihood it looks that
without the Hixie75 flag, Safariis not getting connected to the
stream. In addition in the samples page (http://code.google.com/p/
websocket-sample/wiki/HowToInstallMod_pywebsocket) it looks like
Safari needs the draft75 flag.

Also hixie75 flag is not case-insensitive as if I use CamelCase it is
not getting properly evaluated and I get the same error while
connecting.

~ Barada

On Dec 15, 4:30 pm, Takashi Toyoshima <toyos...@google.com> wrote:
> Hi Barada,
>
> Thanks for your investigation.
> But, it looks curious.
>
> In my test environment, allow_draft75 value was 'On'.

> Actually, we improved its value handling in r570, likehttp://code.google.com/p/pywebsocket/source/diff?spec=svn570&r=570&fo...

Reply all
Reply to author
Forward
0 new messages