jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
645 stars 116 forks source link

always got the 404 error #45

Closed dukeduck1984 closed 5 years ago

dukeduck1984 commented 6 years ago

Hi,

I always got the "404 Not Found Nothing matches the given URI" error, although I could connect to the server.

The similar issue was reported here too: https://www.cnx-software.com/2017/10/16/esp32-micropython-tutorials/

I used the loboris fork of the Micropython firmware for ESP32: https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/. The MicroWebSrv module was frozen in the firmware.

Here is my code:

from microWebSrv import MicroWebSrv

ws = MicroWebSrv()

@MicroWebSrv.route('/')
def handlerFuncGet(httpClient, httpResponse):
    content = """\
    <!DOCTYPE html>
    <html>
        <h1>hello world</h1>
    </html>
    """
    print(content)

@MicroWebSrv.route('/<action>')
def handlerFuncEdit(httpClient, httpResponse, routeArgs):
    action = routeArgs['action']
    print(action)

ws.Start()

Thanks in advance for your help.

-Kaiyuan

formica-multiuso commented 5 years ago

Hi have the exact same issue. Any idea?

jczic commented 5 years ago

Hello, root folder is "/flash/www" by default. You can change it in the constructor of MicroWebSrv. This is maybe the problem ?

dukeduck1984 commented 5 years ago

Hi,

Thanks for the reply.

So I will need the 'www' folder under flash root even it's empty?

-Kaiyuan

jczic commented 5 years ago

Oh no sorry, your problem isn't the root folder. Just, you must call a function to write the content, see httpResponse.WriteResponseOk() or others in the readme page.

dukeduck1984 commented 5 years ago

Ah! I got you! I should use httpResponse.WriteResponseOk() instead of print(), correct?

Thanks for pointing this out.

-Kaiyuan

dukeduck1984 commented 5 years ago

Ah! I got you! I should use httpResponse.WriteResponseOk() instead of print(), correct?

Thanks for pointing this out.

-Kaiyuan

jczic commented 5 years ago

Yes !

jczic commented 4 years ago

Hello,

I released a fully new version (v2.0) of my web server here : github.com/jczic/MicroWebSrv2. Open source MIT, fully asynchronous, more robust, more fast and more efficient! It is delivered with a good documentation.

Thank you for your support and feedback. ☺️

Jean-Christophe Bos

Le jeu. 11 oct. 2018 à 11:46, Kaiyuan notifications@github.com a écrit :

Ah! I got you! I should use httpResponse.WriteResponseOk() instead of print(), correct?

Thanks for pointing this out.

-Kaiyuan

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jczic/MicroWebSrv/issues/45#issuecomment-428892128, or mute the thread https://github.com/notifications/unsubscribe-auth/AAegLINztGouZOvXFZ50m4wOAKMF1tLXks5ujxNugaJpZM4XF-6I .

--

Sincèrement,