question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebREPL Connection lost (EOF) in Thonny 3.3.3 ESP8266 MicroPython v.1.14

See original GitHub issue

I am using ESP8266 running the latest MicroPython v1.14. I have configured WebREPL with a password and can connect to it with the “official” WebREPL client for MicroPython (webrepl.html). The same does not work in Thonny, I have the following messages, trying to connect, then Stop/Restart backend couple of times as suggested by the first error message, also tried to turn on/off ESP8266 and restart Thonny:

MicroPython v1.14 on 2021-02-02; ESP module with ESP8266

Type "help()" for more information.
>>> 
-----------------------------------------------------------------------------------------------------------

WebREPL connected

Connection lost (EOF)

Use Stop/Restart to reconnect.

-----------------------------------------------------------------------------------------------------------
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 827, in transfer_data
    message = await self.read_message()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 910, in read_message
    return frame.data.decode("utf-8") if text else frame.data
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Thonny\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Program Files (x86)\Thonny\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 54, in _wrap_ws_main
    loop.run_until_complete(self._ws_main())
  File "C:\Program Files (x86)\Thonny\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 66, in _ws_main
    await asyncio.gather(self._ws_keep_reading(), self._ws_keep_writing())
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 123, in _ws_keep_writing
    await self._ws.send(payload)
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 555, in send
    await self.ensure_open()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 812, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason


-----------------------------------------------------------------------------------------------------------------
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 827, in transfer_data
    message = await self.read_message()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 910, in read_message
    return frame.data.decode("utf-8") if text else frame.data
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Thonny\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Program Files (x86)\Thonny\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 54, in _wrap_ws_main
    loop.run_until_complete(self._ws_main())
  File "C:\Program Files (x86)\Thonny\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 66, in _ws_main
    await asyncio.gather(self._ws_keep_reading(), self._ws_keep_writing())
  File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\plugins\micropython\webrepl_connection.py", line 123, in _ws_keep_writing
    await self._ws.send(payload)
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 555, in send
    await self.ensure_open()
  File "C:\Program Files (x86)\Thonny\lib\site-packages\websockets\protocol.py", line 812, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason


-----------------------------------------------------------------------------------------------------------------

My environment: Windows 10 Home, Thonny 3.3.3, Python 3.7.9 (32 bit) Tk 8.6.9 COM6 connection in Thonny works as expected, I can connect to ESP8266, run Python code and upload files, but I would like to use WebREPL if possible.

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aziubincommented, Feb 20, 2021

Verified that Thonny 3.3.4 can open MicroPython v.1.14 WebRepl (ESP8266).

0reactions
segankucommented, Feb 20, 2021

It appears that Thonny 3.3.4 + MicroPython 1.14 are still having problems when a remote WebREPL connects:

ERROR   thonny.plugins.micropython.backend: PROBLEM WITH THONNY'S BACK-END:
Traceback (most recent call last):
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\backend.py", line 340, in _handle_normal_command
    response = handler(cmd)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\backend.py", line 636, in _cmd_get_globals
    "{name : (__thonny_helper.repr(value), id(value)) for (name, value) in globals().items() if not name.startswith('__')}"
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\backend.py", line 549, in _evaluate
    out, err = self._execute(script, capture_output=True)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\backend.py", line 505, in _execute
    self._execute_with_consumer(script, consume_output)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\bare_metal_backend.py", line 708, in _execute_with_consumer
    self._submit_code(script)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\bare_metal_backend.py", line 567, in _submit_code
    self._submit_code_via_raw_paste_mode(to_be_sent)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\bare_metal_backend.py", line 657, in _submit_code_via_raw_paste_mode
    self._raw_paste_write(script_bytes)
  File "C:\Users\montg\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\micropython\bare_metal_backend.py", line 691, in _raw_paste_write
    raise AssertionError("Unexpected read during raw paste: {}".format(data))
AssertionError: Unexpected read during raw paste: bytearray(b'p')
term: Exception in write() method, deactivating: OSError: [Errno 104] ECONNRESET
�

I see this issue is now closed, so maybe I’ll start a new thread. I was kinda thinking these issues were probably somewhat related.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webrepl problem - MicroPython Forum (Archive)
Hello, im trying to setup webrepl on my bord, loin32 boot.py ... STA_IF) if not sta_if.isconnected(): print('connecting to network.
Read more >
Wireless MicroPython Programming With Thonny - Hackaday
For Linux and Mac simply doing sudo apt install thonny or brew install ... Fill in the WebREPL URL and password — you...
Read more >
how do I read a file in desktop on esp8266 micropython?
I using the mac os and thonny micropython ide. the file is called graph.txt on the desktop. when i try reading it from...
Read more >
MicroPython ESP32 pro-tip: Use WebREPL within Thonny
We've learned how to wirelessly connect and upload new code to an ESP32 using WebREPL before. But often, the repetitive process of: editing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found