| | |
Web Server code not working
![]() |
•
•
Join Date: Jun 2009
Posts: 12
Reputation:
Solved Threads: 0
Hi,
I'm trying to build a web server in Python, and here is what I have so far:
I do not get any errors, however when it runs the shell opens and nothing happens.
What changes to this code would I do to make it work?
Thanks.
I'm trying to build a web server in Python, and here is what I have so far:
Python Syntax (Toggle Plain Text)
Code: from http.server import HTTPServer, BaseHTTPRequestHandler class RequestHandler(BaseHTTPRequestHandler): def _writeheaders(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() def do_HEAD(self): self._writeheaders() def do_GET(self): self._writeheaders() self.wfile.write("""<HTML> <HEAD><TITLE>Sample title</TITLE></HEAD> <BODY>sample text</BODY> </HTML>""") serveraddr = ('', 8080) srvr = HTTPServer(serveraddr, RequestHandler) srvr.serve_forever()
I do not get any errors, however when it runs the shell opens and nothing happens.
What changes to this code would I do to make it work?
Thanks.
•
•
Join Date: Jun 2009
Posts: 12
Reputation:
Solved Threads: 0
Thanks. When I run it and go to it via localhost in my browser (Safari) I get this in the Shell and I get a blank browser page:
Python Syntax (Toggle Plain Text)
localhost - - [11/Jun/2009 16:55:55] "GET / HTTP/1.1" 200 - ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 54107) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/socketserver.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/socketserver.py", line 307, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/socketserver.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/socketserver.py", line 614, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/http/server.py", line 363, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/http/server.py", line 357, in handle_one_request method() File "/Users/brennonwilliams/Documents/basichttp.py", line 19, in do_GET </HTML>""") File "/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/socket.py", line 219, in write return self._sock.send(b) TypeError: send() argument 1 must be bytes or buffer, not str ----------------------------------------
Why don't you try sending something simpler... this is an example i found from googling:
python Syntax (Toggle Plain Text)
class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write("Hello World!")
![]() |
Similar Threads
- Web Server Path for Access DB (ASP.NET)
- how would you apply threading to a web server application (C++)
- How to check if extensions code are working (C++)
- Windows: Installing A Web Server Cache on Apache (Linux Servers and Apache)
- Connecting to web server using client desktop application (Visual Basic 4 / 5 / 6)
- Uploading images to the Web Server using ASP (ASP)
- simple python web server (Python)
- Win95 and Personal Web Server 1.0a Crashing Issue (Windows 95 / 98 / Me)
- Need a web server in intranet serve a external system (Networking Hardware Configuration)
- web server not working? (Networking Hardware Configuration)
Other Threads in the Python Forum
- Previous Thread: Stuck with Mechanize in Script
- Next Thread: Text colour editing?
| Thread Tools | Search this Thread |
alarm app beginner cipher cmd coordinates cx-freeze data decimals development dictionary directory dynamic error examples feet file float format function generator getvalue gui halp homework http images import input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse mysqldb number numbers output parsing path port prime programming projects push py2exe pygame pyglet pymailer pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation split sqlite ssh string strings sudokusolver terminal text thread threading time tlapse tooltip tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo verify vigenere web webservice wikipedia wx.wizard wxpython xlwt







