Hugo Trentesaux
Hugo Trentesaux

Reputation: 1989

windows python http.server can not be reached

I am used to run python3 -m http.server from GNU/Linux systems to serve files locally.

I had to do this on windows, and although python replies:

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

I can not reach the server.

Browsers give this:

| address                 | Firefox response | Chrome response         |
| ----------------------  | ---------------  | --------------          |
| http://localhost:8000/  | nothing          | ERR_EMPTY_RESPONSE      |
| http://0.0.0.0:8000/    | nothing          | ERR_ADDRESS_INVALID     |
| http://127.0.0.1/       | nothing          | ERR_CONNECTION_REFUSED  |

I tried to deactivate the firewall and to add rules allowing TCP connections to this port (not 80, as shown above), but did not succeed. I am not a windows user, so I might have missed something evident...

Other questions (1, 2) seem to say that it is easy.

Upvotes: 1

Views: 4645

Answers (2)

Petr L.
Petr L.

Reputation: 480

I had the same issue and solved it by changing the network type to private in Windows 10:

  1. Open the WiFi taskbar buttton
  2. You will see the network your connected to, click the properties link
  3. Windows Settings open, Change the network type to Private (computer visible for sharing printers and documents. The network type was previosly Public (computer hidden from other devices in the network and can't be used to share printers and files) and that didn't work.

Now, when the network type is private, I can access localhost using

http://127.0.0.1:8000/

in Firefox and

py -m http.server

in the command prompt

Hope this helps!

Upvotes: 0

Hugo Trentesaux
Hugo Trentesaux

Reputation: 1989

It happened to be a localhost binding problem.

python -m http.server --bind localhost

solved it. Python response was:

Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...

Hope it can help someone else!

Upvotes: 4

Related Questions