【问题标题】:How i can get a get-server-time with python?我如何使用 python 获得获取服务器时间?
【发布时间】:2020-04-05 19:29:10
【问题描述】:

我需要用get-server-time在python上做一个简单的脚本,它可以从服务器获取时间,怎么能得到它?

【问题讨论】:

    标签: python server get


    【解决方案1】:

    首先,您需要创建一个服务器。最简单的选择之一是为此使用第三方模块。例如,flask 是一个流行的带有内置服务器的 Web 框架:

    from datetime import datetime
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
        now = datetime.now()
        current_time = now.strftime("%H:%M:%S")
        return current_time
    

    将其保存到server.py,然后使用:

    > export FLASK_APP=server.py
    > flask run
     * Running on http://127.0.0.1:5000/
    

    从浏览器或使用wget http://127.0.0.1:5000/curl http://127.0.0.1:5000/ 访问http://127.0.0.1:5000/

    【讨论】:

      猜你喜欢
      • 2011-05-25
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 2018-07-12
      • 2014-08-03
      相关资源
      最近更新 更多