python-websockets / websockets

Library for building WebSocket servers and clients in Python

Home Page:https://websockets.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling handshake that returns a status code other than 101?

daveisfera opened this issue · comments

I'm using websockets as a client to test the server and the handshake first does a 401 so it can return a nonce that the client is supposed to use. I've tried implementing handshake in WebSocketClientProtocol to handle this but couldn't get it to send a follow on request/connection.

Is there a way to accomplish this?

I don't know any good way to do this.

The least aggravating option in the current state of websockets may be:

  • perform a HTTP request with an API that give you access to the underlying socket object
  • get the 401 answer, extract the nonce, and build the authenticated request
  • use the sock and extra_headers arguments of connect to reuse the same connection and send the correct headers

This is a duplicate of #784, isn't it?

Thanks for the reply! Sounds like I'll close this out since it's not currently supported and I'll use a workaround like you're suggesting

As far as the other issues goes, I believe the concept of supporting authentication is similar but the details are different