[Tutor] Making a simple web server in Python

Michael bridges micha_el2003 at yahoo.com
Tue May 31 02:37:24 CEST 2011


when running code from http://fragments.turtlemeat.com/pythonwebserver.php: [putting http://localhost:81/index.html in broswer]
this error happens:
>>> 
Traceback (most recent call last):
  File "C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py", line 65, in <module>
    main()
  File "C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py", line 56, in main
    server = HTTPServer(('', 80), MyHandler)
  File "C:\Python31\lib\socketserver.py", line 400, in __init__
    self.server_bind()
  File "C:\Python31\lib\http\server.py", line 127, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Python31\lib\socketserver.py", line 411, in server_bind
    self.socket.bind(self.server_address)
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
>>> 


[with port 80 changed to port 81, can not use port 80 for some reason]
this error happens:
>>> 
started httpserver...
michaeleric-PC - - [30/May/2011 15:00:24] "GET /index.html HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 62592)
Traceback (most recent call last):
  File "C:\Python31\lib\socketserver.py", line 281, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python31\lib\socketserver.py", line 307, in process_request
    self.finish_request(request, client_address)
  File "C:\Python31\lib\socketserver.py", line 320, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python31\lib\socketserver.py", line 614, in __init__
    self.handle()
  File "C:\Python31\lib\http\server.py", line 352, in handle
    self.handle_one_request()
  File "C:\Python31\lib\http\server.py", line 346, in handle_one_request
    method()
  File "C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py", line 20, in do_GET
    self.wfile.write(f.read())
  File "C:\Python31\lib\socket.py", line 219, in write
    return self._sock.send(b)
TypeError: must be bytes or buffer, not str
----------------------------------------
^C received, shutting down server
>>> 

changing to port 29876 gives same error & did not want to stop, kept restarting.

[putting http://localhost/index.html in broswer]
gives 404 error

[putting http://localhost/index.esp in broswer]
gives 404 error



More information about the Tutor mailing list