Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webserver.py giving error file not found #147

Open
AnshuTrivedi opened this issue Jul 9, 2022 · 0 comments
Open

webserver.py giving error file not found #147

AnshuTrivedi opened this issue Jul 9, 2022 · 0 comments

Comments

@AnshuTrivedi
Copy link

Python Version: Python 3.7.5
O.S : Ubuntu 18.04.5

I'm not using vagrant setup. Any help appreciated.

Error :

Error response
Error code: 404
Message: File not found.

Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.

Webserver file code:

`from http.server import BaseHTTPRequestHandler,SimpleHTTPRequestHandler, HTTPServer

class webhandler(SimpleHTTPRequestHandler):
      def do_Get(self):
        try:
          if self.path.endswith('/hello'):
            self.send_response(200)
            self.send_header('Content-type','text/html')
            self.end_headers()
            output = ''
            output +=f"<html><body>Hello!</body></html>"
            self.wfile.write(bytes(output,"utf8"))
      
            return 

        except IOError:
              self.send_error(404,"File not found %s" % self.path)
               




def main():
  try:
    port = 8080
    server = HTTPServer(("",port),webhandler)
    print("Web server running on port %s" % port)
    server.serve_forever()
  except KeyboardInterrupt:
      print("^c entered Stopping webserver...")
      server.socket.close()

if  __name__=='__main__':
    main()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant