jczic / MicroWebSrv2

The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
https://github.com/jczic/MicroWebSrv2
MIT License
655 stars 97 forks source link

Server redirects too many times. #10

Closed aqieez closed 4 years ago

aqieez commented 4 years ago

I am using lopy4 with Pysense. I have copied all files of the project into lopy4. After connecting with lopy4 wifi, in my browser url i am typing http://192.168.4.1/ and hitting enter. But i am getting error 192.168.4.1 redirected you too many times. I am having this issue after new update on MicroWebSrv2 This the output i am getting in Atom console.

MWS2-INFO> Server listening on 0.0.0.0:80. MWS2-INFO> Starts the managed pool to wait for I/O events. MWS2-DEBUG> From 192.168.4.2:50974 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:50976 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:52594 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:52596 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:52646 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:52656 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:52658 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53452 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53454 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53472 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53474 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53476 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53486 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53488 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53498 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53500 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53510 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53610 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53650 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53672 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53674 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53684 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53686 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53708 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53794 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53804 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53806 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53816 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53818 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53876 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53878 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53888 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53890 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53900 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53908 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53960 GET / >> [307] Temporary Redirect MWS2-DEBUG> From 192.168.4.2:53962 GET / >> [307] Temporary Redirec Any idea what is wrong? is it some kinda permission problem or something? Please help.

jczic commented 4 years ago

Hi, This redirection exists because in main.py, there is the next line to catch not found pages : mws2.NotFoundURL = '/' Also, the default root path for files is www. Do you have this folder at /flash/www on your LoPy? (File /flash/www/index.html must be found.)

aqieez commented 4 years ago

Hi, Thanks for replying, I am uploading all files and folder to LoPy. I can clearly see when I upload the files to my LoPy, in Atom console, it's writing all folders and files. www is also being uploaded in LoPy, but still getting too many time redirection error.

jczic commented 4 years ago

All files are in / or "/flash" ? What is the current directory ? You can set the web path files with RootPath property like : mws2.RootPath = 'flash/www' The example code (main.py) with package works on Pycom modules like LoPy. You could see all files in your LoPy Flash with FTP (ftp://192.168.4.1 L:micro P:python) Also, I've a LoPy4R and that's works without problem.

jczic commented 4 years ago

Hi, can you retry with the last release v2.0.4 please? :) Thank you!

aqieez commented 4 years ago

Hi there, Sorry for the late response. I was traveling for last week. I will try it today and let you know. Thanks for your support

jczic commented 4 years ago

No problem! :')

aqieez commented 4 years ago

Hi, @jczic I have checked the latest version and it's working like a pro... Cheers :)

aqieez commented 4 years ago

But I have another question... Please

@WebRoute(POST, '/test-post', name='TestPost2/2') def RequestTestPost(microWebSrv2, request) : data = request.GetPostedURLEncodedForm() try :

    first = data['Firstname']
    last  = data['Lastname']

    f = open('data.txt','w')
    f.write(first+'\n')
    f.write(last)
    f.close()

except :
    request.Response.ReturnBadRequest()
    return
content   = """\
<!DOCTYPE html>
<html>
    <head>
        <title>POST 2/2</title>
    </head>
    <body>
        <h2>MicroWebSrv2 - POST 2/2</h2>
        your information has been saved.. Restrating the microcontroller :)<br />
    </body>
</html>
"""
request.Response.ReturnOk(content)
machine.reset()

After saving the first name and last name to a file. I want to return a response and then I want to reboot the microcontroller. but It is only rebooting the but not showing the response in the browser.

jczic commented 4 years ago

👍 About your question, there is actually no method to handle the end of the response sent... I can add an event property in few time. You'll be able to have a method to handle this with or without a keep-alive context.

chris-reichl commented 2 years ago

I also received a [307] Temporary Redirect error and was able to solve the problem as follows:

Cause of [307] Temporary Redirect error: I had the problem that files like .ico, .png and .pdf are excluded from uploading with Pymark. So they were not present in the file system of the microcontroller and could not be found, which then led to the [307] Temporary Redirect error.

Solution: The files that are to be taken into account during upload must be explicitly specified in the project settings of Pymark. In my case I had to add the following line, then everything worked fine: "sync_file_types": "py,txt,log,json,xml,html,js,css,mpy,pdf,ico,png,svg"

image

Information about the microcontroller: Pycom MicroPython 1.20.2.r6 [v1.11-c5a0a97] on 2021-10-28; FiPy with ESP32