0

I have a small-scale python server to handle some incoming requests over the network.

class MyTCPHandler(socketserver.BaseRequestHandler):


    def handle(self):

        current_date = date.today()
        formatted_date = current_date.strftime("%m/%d/%Y")

        ...

I am calling the date.today() routine inside the handle() function of the server. The server is instantiated and launched in the main function here:

if __name__ == "__main__":
    HOST, PORT = "169.229.130.11", 8000

    # Create the server, binding to localhost on port 8000
    server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)

    # Activate the server; this will keep running until you
    # interrupt the program with Ctrl-C
    server.serve_forever()

It looks like the date.today() function is returning the date that the python program was started on the command line, which was several weeks ago.

If handle() is called for each incoming request to the server, why is date.today() not refreshing?

  • What is the definition of "date" object/class ? Is it "from datetime import date" ? – poleszcz Sep 07 '21 at 22:10
  • Yes: "from datetime import date" – Preetham Solomon Sep 07 '21 at 22:14
  • I think there must be some confusion and missinterpretation of the log. Simple test with running this server script and sending requests manually (eg. curl -XGET 127.0.0.1:8000) shows that date.today() returned value changes in line with system date (I've changed date manually on os between triggering consecutive requests). – poleszcz Sep 08 '21 at 06:39

0 Answers0