MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
uxhamby
Posts: 34
Joined: Thu Nov 14, 2019 9:47 pm

Re: MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Post by uxhamby » Wed Jul 29, 2020 3:28 am

Hi,

I am having a similar error.

Does this:
MicroWebSrv2Exception: Cannot load module "WebSockets".
imply that space to load the "WebSockets" module is not available ?

FWIW, I am attempting to run MicroWebSrv2 on one of those 38 pin ESP32 WROOM modules from eBay.

Code: Select all

Connection successful
('192.168.55.140', '255.255.255.0', '192.168.55.1', '192.168.55.3')
Host Name:  ESP32_5
GMT time:    (2020, 7, 29, 3, 6, 54, 2, 211)
Local time:  (2020, 7, 28, 23, 6, 54, 1, 210)

       ---------------------------
       - Python pkg MicroWebSrv2 -
       -      version 2.0.6      -
       -     by JC`zic & HC2     -
       ---------------------------

 + [@WebRoute] GET /test-redir
 + [@WebRoute] GET /test-post (TestPost1/2)
 + [@WebRoute] POST /test-post (TestPost2/2)

Traceback (most recent call last):
  File "main.py", line 153, in <module>
  File "MicroWebSrv2/microWebSrv2.py", line 136, in LoadModule
MicroWebSrv2Exception: Cannot load module "WebSockets".
Thanks,

Brian H.

aihrig
Posts: 6
Joined: Mon Aug 17, 2020 10:25 pm

Re: MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Post by aihrig » Thu Aug 20, 2020 3:20 am

MicroWebSrv2Exception: Cannot load module "WebSockets"
I'm also getting this error on an ESP32. Is this something that would be solved by freezing the module?

caoc10
Posts: 1
Joined: Thu Aug 27, 2020 3:18 pm

Re: MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Post by caoc10 » Thu Aug 27, 2020 3:38 pm

Hi everyone!

I'm new here and kind of new in Micropython! :D
I've successfully built the firmware with MicroWebSrv2 as a frozen module and checked that everything works.
(If any of you are in trouble and want this firmware just tell me and I will send it without problem)

So, I've been struggling with a problem that seem kind of simple (maybe I am looking for a complex solution when it is really simple).
:?
I am able to fetch html pages when I call it directly like this:

Code: Select all

http://localhost/test.html
Although, I want to build a web route where I do some processing and open one page or another according with the processing done.
Here it is an example of the code:

Code: Select all

@WebRoute(POST, '/authentication', name='auth')
def Authentication(microWebSrv2, request):
    data = request.GetPostedURLEncodedForm()
    username = binascii.hexlify(hashlib.sha256(data["username"]).digest()).decode('ascii')
    password = binascii.hexlify(hashlib.sha256(data["password"]).digest()).decode('ascii')
    user = main.dao.checkAuthentication(username, password, data["tipo"])
    if user != None:
        request.Response.ReturnRedirect("adminMenu.html")
    else:
        request.Response.ReturnRedirect("/")
But it simply don't work!
The redirection is being treated as a POST and I always get a "Method Not Allowed" on my page.
Is this the correct way to answer with a html page to a request?
Or is there a simpler way that I am not seeing?

Thank you!

micromonte
Posts: 1
Joined: Tue Mar 02, 2021 6:27 pm

Re: MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Post by micromonte » Tue Mar 02, 2021 6:31 pm

MicroWebSrv2 is incredibly well done. Unfortunately, it crashes after a while on pycom Wipy for no clear reason. Reproduce the failure by refreshing the home page a number of times.

It's frustrating that such a good project cant be used on pycom boards.

yawipyuser
Posts: 1
Joined: Sat Jan 22, 2022 4:01 pm

Re: MicroWebSrv2, new asynchronous Web server for MicroPython (+Routes +WebSockets +Template engine).

Post by yawipyuser » Sat Jan 22, 2022 4:12 pm

micromonte wrote:
Tue Mar 02, 2021 6:31 pm
Reproduce the failure by refreshing the home page a number of times.
I encountered the same issue, on a Lopy 4. Server just stops responding, no additional output.
Stop and start again work without issue, and then it locks up again.

Traced it back to ECONNRESET in the TCP socket.
To mitigate (i suspect the core issue is somewhere else, but this allows the server to run, and clients usually request the files again...):

Start in libs/XAsyncSockets.py Line 664:
https://github.com/jczic/MicroWebSrv2/b ... ts.py#L664

Replace:

Code: Select all

           try :
                n = self._socket.send(self._wrBufView)
            except :
                return
            self._wrBufView = self._wrBufView[n:]
with:

Code: Select all

try :
    n = self._socket.send(self._wrBufView)
    self._wrBufView = self._wrBufView[n:]
except Exception as ex:
    if ex.args[0] == errno.ECONNRESET:
        print("Force closing socket after reset.")
        self._close(XClosedReason.Error, triggerOnClosed=False)
    return
This closes the socket on reset, and server runs fine.
If anybody knows where the real issue is hiding, please enlighten me :D

Post Reply