aio-libs/aiohttp · error · HTTPBadRequest
No WebSocket UPGRADE hdr: {headers.get(hdrs.UPGRADE)} Can "
Error message
No WebSocket UPGRADE hdr: {headers.get(hdrs.UPGRADE)}
Can "Upgrade" only to "WebSocket". What it means
Error "No WebSocket UPGRADE hdr: {headers.get(hdrs.UPGRADE)} Can "Upgrade" only to "WebSocket"." thrown in aio-libs/aiohttp.
Source
Thrown at aiohttp/web_ws.py:275
async def prepare(self, request: BaseRequest) -> AbstractStreamWriter:
# make pre-check to don't hide it by do_handshake() exceptions
if self._payload_writer is not None:
return self._payload_writer
protocol, writer = self._pre_start(request)
payload_writer = await super().prepare(request)
assert payload_writer is not None
self._post_start(request, protocol, writer)
await payload_writer.drain()
return payload_writer
def _handshake(
self, request: BaseRequest
) -> tuple["CIMultiDict[str]", str | None, int, bool]:
headers = request.headers
if "websocket" != headers.get(hdrs.UPGRADE, "").lower().strip():
raise HTTPBadRequest(
text=(
f"No WebSocket UPGRADE hdr: {headers.get(hdrs.UPGRADE)}\n Can "
'"Upgrade" only to "WebSocket".'
)
)
if not request._message.upgrade:
raise HTTPBadRequest(
text=f"No CONNECTION upgrade hdr: {headers.get(hdrs.CONNECTION)}"
)
# find common sub-protocol between client and server
protocol: str | None = None
if hdrs.SEC_WEBSOCKET_PROTOCOL in headers:
req_protocols = [
str(proto.strip())
for proto in headers[hdrs.SEC_WEBSOCKET_PROTOCOL].split(",")
]View on GitHub (pinned to c0ef574e29)
When it happens
Trigger: Thrown at aiohttp/web_ws.py:275 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/c065460ba867d6f6.json.
Report an issue: GitHub.