我使用Chrome 14.这是我的python websocket服务器代码片段:
global guid
key = hashlib.sha1(headers['Sec-WebSocket-Key']+guid).digest()
key.encode('iso-')
headers['Sec-WebSotycket-Accept'] = base64.b64encode(key)
print headers['Sec-WebSocket-Accept']
handshake = '\
HTTP/1.1 101 Switching Protocols\r\n\
Upgrade: %s\r\
Connection: %s\r\
Sec-WebSocket-Accept: %s\r\
Sec-WebSocket-Protocol: base64\r\
' %(headers['Upgrade'],headers['Connection'],headers['Sec-WebSocket-Accept'])
try:
self.conn.send(handshake)
except Exception as e:
print e
为什么Chrome客户端不接受此服务器发送握手?
Request URL:ws://127.0.0.1:1234/
Request Headers
Connection:Upgrade
Host:127.0.0.1:1234
Sec-WebSocket-Key:xuV2xuiXxqL4Hwcxjg9dJA==
Sec-WebSocket-Origin:null
Sec-WebSocket-Version:8
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
答案 0 :(得分:0)
它可能是您服务器代码的第4行吗?您的密钥“Sec-WebSotycket-Accept”看起来拼写错误。