D
D
demsp2018-09-01 21:03:15
Python
demsp, 2018-09-01 21:03:15

How to set up a server in the cloud in Python?

Run this server on localhost

from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer

class HttpProcessor(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('content-type','text/html')
        self.end_headers()
        self.wfile.write("hello!")


serv = HTTPServer(("localhost",80),HttpProcessor)
serv.serve_forever()

On a cloud service, such a script, of course, does not run. How to run codeanywhere.com cloud service?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
igorzakhar, 2018-09-02
@demsp

5b8aff214494c839016206.png
Create a project:
Create a "Connection" (there are different options, I chose "Container" for demonstration):
After creation, information on the container will appear, where links are indicated on which your application will be available:
Create a file "File" -> "New File" (there is option to "drag and drop" the file from your PC). We paste your code:
Correct (instead of "localhost" we write "0.0.0.0" and select a port from the range 1024-9999):

from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer

class HttpProcessor(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('content-type','text/html')
        self.end_headers()
        self.wfile.write("hello!")
serv = HTTPServer(("0.0.0.0",8080),HttpProcessor)
serv.serve_forever()

Run the script:
Follow the link that is specified in "Info" (protocol "http" ), do not forget to specify the port (in our case 8080):
5b8b01977adb3008278544.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question