websocket-client: Crash when server doesn't return a Reason-Phrase (status text) after HTTP/1.1 101
If the HTTP server doesn’t return 'HTTP/1.1 101 Switching Protocols as it’s supposed to do, but instead just HTTP/1.1 101, websockets-client crashes with the following stacktrace:
Traceback (most recent call last):
File "./test.py", line 7, in <module>
ws.connect('wss://www.example.com/')
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 220, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "/usr/local/lib/python3.6/site-packages/websocket/_handshake.py", line 69, in handshake
status, resp = _get_resp_headers(sock)
File "/usr/local/lib/python3.6/site-packages/websocket/_handshake.py", line 133, in _get_resp_headers
status, resp_headers, status_message = read_headers(sock)
File "/usr/local/lib/python3.6/site-packages/websocket/_http.py", line 245, in read_headers
status_message = status_info[2]
IndexError: list index out of range
I’ve fixed it locally, I’m just putting this here for the PR
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15
It should be existing in the latest release. I definitely see it at lines 318-319 of the current latest commit. I can also see it in the wheel from PyPI. I also created a new virtual environment and it was still there.
There was something else going wrong with your setup. The bug has been corrected for 2 years now.
I have run into the same issue with Tomcat version 8 and jsr 356 for websocket which does not send back the Reason Phrase and causes this crash.
I agree. It seems that Reason-phrase is optional in HTTP Response status line https://stackoverflow.com/questions/17517086/can-an-http-response-omit-the-reason-phrase