【问题标题】:Python http.server not print logPython http.server 不打印日志
【发布时间】:2017-11-05 13:36:39
【问题描述】:

我正在使用 Git Bash 通过 $ python3 -m http.server 8000 运行一个简单的本地服务器

Git Bash 永远不会打印出它正在运行,也不会得到请求的日志。我可以访问http://localhost:8000/,所以该命令正在运行。如何让 git bash 打印日志?

【问题讨论】:

标签: python mingw git-bash


【解决方案1】:

这似乎是 mingw 下的行缓冲的一般问题。您应该能够通过避免缓冲输出来解决此问题,在您的情况下可以通过

$ python -u -m http.server 8080

这按预期工作

$ uname -a
MINGW64_NT-6.3 - 2.5.0(0.295/5/3) 2016-03-31 18:47 x86_64 Msys

【讨论】:

  • 为我工作。谢谢!
【解决方案2】:

从“什么”Git Bash 来看,它似乎是 cygwin 的精简版。我刚刚运行“python3 -m http.server 8000”,得到以下日志输出:

$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Jun/2017 20:15:10] code 404, message File not found
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2017 20:15:10] code 404, message File not found
127.0.0.1 - - [04/Jun/2017 20:15:10] "GET /favicon.ico HTTP/1.1" 404 -

似乎 git bash 没有正确记录(输出)。

尝试使用 Ubuntu 或 Centos 在 vi​​rtualbox / vagrant -> 中运行“python3 -m http.server 8000”。

【讨论】:

    猜你喜欢
    • 2015-07-08
    • 2016-03-10
    • 2021-12-09
    • 2017-02-23
    • 2014-08-30
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多