Behnam Beladi
Behnam Beladi

Reputation: 13

How Can I open an html file on a local server by using python (python -m http.server)?

When I try to run the following code in the directory where my index.html file is saved:

python -m http.server 8888

I get this error:
This site can’t be reachedThe webpage at http://0.0.0.0:8888/index.html might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID

How can I solve this issue?
thanks

Upvotes: 1

Views: 2493

Answers (2)

AndradeL
AndradeL

Reputation: 74

In Python3 I had the above issue on the computer where I was seconded to a company and couldn't bring my own equipment to. "Simply" changing 0.0.0.0 to 127.0.0.1 didn't do the trick for me on the locked computer, so the issue was resolved by: pyCharm's terminal:

python -m http.server 9000 --directory 'C:\Users\PathToYourHTMLFile\' --bind 127.0.0.1

Then in the webbrowser type:

127.0.0.1:9000/PathToYourHTMLFileFromCurrentFolder 

Upvotes: 0

saquintes
saquintes

Reputation: 1089

0.0.0.0 is not a routable address. You put 0.0.0.0 on the command line sometimes to let the server know to listen on any interface. But to route to yourself, you must use the IP address 127.0.0.1.

Upvotes: 1

Related Questions