Quick question about http_server_simplistic.py at examples folder
Quick question about http_server_simplistic.py at examples folder
I copy and pasted using Ctrl-E this example found here https://github.com/micropython/micropyt ... plistic.py but although I receive a 200 code the page is empty. Am i doing something wrong?
Re: Quick question about http_server_simplistic.py at examples folder
That example didn't work for me either when pasted with the REPL...it's important the HTTP response have \r\n as the newline characters and those might be getting lost by pasting it in.
The following version of it worked when pasting it in. The only change I made was to explicitly use \r\n for the newlines in the HTTP response rather than relying on whatever the newlines ended up being.
The following version of it worked when pasting it in. The only change I made was to explicitly use \r\n for the newlines in the HTTP response rather than relying on whatever the newlines ended up being.
Code: Select all
try:
import usocket as socket
except:
import socket
CONTENT = b"""\
HTTP/1.0 200 OK\r\n\
\r\n\
Hello #%d from MicroPython!
"""
def main():
s = socket.socket()
ai = socket.getaddrinfo("0.0.0.0", 8080)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(5)
print("Listening, connect your browser to http://<this_host>:8080/")
counter = 0
while True:
res = s.accept()
client_s = res[0]
client_addr = res[1]
req = client_s.recv(4096)
print("Request:")
print(req)
client_s.send(CONTENT % counter)
client_s.close()
counter += 1
print()
main()