Source code for the three-part series of articles "Let's Build A Web Server".
rspivak / lsbaws Goto Github PK
View Code? Open in Web Editor NEWLet's Build A Web Server
License: MIT License
Let's Build A Web Server
License: MIT License
Source code for the three-part series of articles "Let's Build A Web Server".
Hi, thanks for the series. I spend this weekend reading these articles and really enjoy them.
But I am so confused that why 'os._exit(0)' should be in the for loop. Does it mean immediately exit the child process after the first connection?
['pyramidapp']
Traceback (most recent call last):
File "main.py", line 116, in
module, application = app_path.split(':')
ValueError: need more than 1 value to unpack
Program ended with exit code: 1
curl(7.58.0) terminated, without display "Hello, World!".
I think, the 'http_response' is deficient.
With this, it working good:
http_response = b"""\
HTTP/1.1 200 OK
Content-Type: text/html
Hello, World!
"""
I came across the Error if I am not comment the "print" after "os.waitpid" when using the code from you github.
I search solution from the internet, it tell me that maybe caused by lock's problem.
So I comment that code and it runs normally.
(webserver3h.py from your github, I just add some function about handle some encoding for python3)
def grim_reaper(signum, frame):
while True:
try:
pid, status = os.waitpid(
-1, # Wait for any child process
os.WNOHANG # Do not block and return EWOULDBLOCK error
)
print(
'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
)
except OSError:
return
httpd.serve_forever()
File "webserver3.py", line 72, in serve_forever
pid = os.fork()
File "webserver3.py", line 22, in grim_reaper
'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
File "webserver3.py", line 22, in grim_reaper
'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stdout>'>
Hi, I tried the first demo webserver1.py
. When I open the URL http://localhost:8888/hello
in my Firefox, the web page is blank. But, the terminal occurs the following massage:
GET /hello HTTP/1.1
Host: localhost:8888
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
What's wrong?
can you help me debug webapp with django
ile "/usr/local/Cellar/python@2/2.7.15_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/Users/ajmd/code/webserver/helloworld/urls.py" in <module>
1. from django.conf.urls import patterns, include, url
Exception Type: ImportError at /hello
Exception Value: cannot import name patterns
and the source code:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns(
'',
# Examples:
# url(r'^$', 'helloworld.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^hello', 'helloworld.views.index'),
)
Problem:
TypeError: a bytes-like object is required, not 'str'
Solve
http_response = b"""\
HTTP/1.1 200 OK
Hello, World!
"""
Besides having forgotten the parentheses around all the "print" statements in the script for the first part of your tutorial, I get the following error:
"TypeError: a bytes-like object is required, not 'str'" on line 20.
test webservice3e.py with curl commands。There is no socket.error :[Errno 4] Interrupted system call when socket.accetp(). what happened ?
The part2 server request to load the app callable from the djangoapp doesn't work in Django version 1.10.1
The contents of the helloworld/urls.py has to be changed
from:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns(
'',
# Examples:
# url(r'^$', 'helloworld.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^hello', 'helloworld.views.index'),
)
To:
from django.conf.urls import include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/', views.index),
]
After running the pyramid server, I can get the response shown in the browser, but after a few seconds, below error was showing on the console and the server was down:
Traceback (most recent call last):
File "webserver2.py", line 142, in
httpd.serve_forever()
File "webserver2.py", line 41, in serve_forever
self.handle_one_request()
File "webserver2.py", line 51, in handle_one_request
self.parse_request(request_data)
File "webserver2.py", line 64, in parse_request
request_line = text.splitlines()[0]
IndexError: list index out of range
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.