Skip to content

WebREPL doesn't work with websocket in Typescript. 'OSError: Not a websocket request' #8409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bittervan opened this issue Mar 13, 2022 · 1 comment

Comments

@bittervan
Copy link

WebSocket on ESP32 Fails, 'Not a websocket request'


I've been working on build a visual studio code extension for a better developing experience on ESP32, MicroPython. But without any basic knowledge for front-end development, this process is quite tough for me.

To establish a wireless connection, the first thing that came into my mind is that I should check the official tools. So I checked the source code of project [webrepl](https://github.com/micropython/webrepl), a WebREPL terminal client, which also has a coarse front-end written in Javascript.

Problem

It seemed to be simple to connect to the webrepl server running on the board, as the code in [webrepl.html](https://github.com/micropython/webrepl/blob/master/webrepl.html) showed. But when I was using the npm package ws or websocket in Typescript to connect to it, the connection was simply cannot be established. The error in the serial connection illustrated that

Traceback (most recent call last):
  File "webrepl.py", line 43, in accept_conn
  File "websocket_helper.py", line 39, in server_handshake
OSError: Not a websocket request

WebREPL connection from: ('192.168.137.1', 2935)

At first I thought it was just like the old problems, parameters, policies, etc. So I applied WireShark to check the different between the packets sent by webrepl and the Typescript extension written by myself.

Using the ws package to connect:

3$9(N~% }8PF@I{)4S%RE8F

Using Javascript WebSocket to conncet:

FE_BGJ%T(MDXLD635QZTTB4

Having no idea which options to alter, I referred to the [MicroPython](https://github.com/micropython/micropython) project to find out. But the code shows that’s nothing to do with the options.

webkey = None

while 1:
    l = clr.readline()
    if not l:
        raise OSError("EOF in headers")
    if l == b"\r\n":
        break
    #    sys.stdout.write(l)
    h, v = [x.strip() for x in l.split(b":", 1)]
    if DEBUG:
        print((h, v))
    if h == b"Sec-WebSocket-Key":
        webkey = v

if not webkey:
     raise OSError("Not a websocket request")

But how can webkey == None happen? The two packets both have Sec-WebSocket-Key in their fields.

@bittervan
Copy link
Author

Solved. It was my proxy did the job. The go-client was the Clash, deleting keys in my packet.

tannewt added a commit to tannewt/circuitpython that referenced this issue Apr 16, 2025
This allows subfolders to be treated similar to / for multiple
apps within different folders.

Also, fix up the internal current working directory so it doesn't
depend on volumes.

Fixes micropython#9045 and fixes micropython#8409.
tannewt added a commit to tannewt/circuitpython that referenced this issue Apr 22, 2025
This allows subfolders to be treated similar to / for multiple
apps within different folders.

Also, fix up the internal current working directory so it doesn't
depend on volumes.

Fixes micropython#9045 and fixes micropython#8409.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant