Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 webserver not working on Windows 10 #2

Closed
Hans-Zamorano-Matamala opened this issue Apr 17, 2022 · 7 comments
Closed

Python 3 webserver not working on Windows 10 #2

Hans-Zamorano-Matamala opened this issue Apr 17, 2022 · 7 comments

Comments

@Hans-Zamorano-Matamala
Copy link

Hans-Zamorano-Matamala commented Apr 17, 2022

Hi, when trying to run start.ps1 and then opening the suggested URL Chrome indicates that the website is not online, this also happen when trying to open localhost:8080. After modifying start.ps1 to not look for Python (line 46) it works perfectly by using the NodeJS one.

Environment: Windows 10 with Python 3 and NodeJS v17.2.0
Used for: iPhone 7 with iOS 15.4

Hope this info is useful.

@HimbeersaftLP
Copy link
Owner

Hi, thanks for reporting this. I cannot reproduce this on my machine. Can you try removing the "| Out-Null" from this line and seeing if any error appears?

python3.exe -m http.server $PORT --bind $SRV_HOST --directory $DIR 2>&1 | Out-Null

@Hans-Zamorano-Matamala
Copy link
Author

Hi, thanks for your reply. If I remove the line it throws an error specfying that python3.exe was not found. Effectively I can run python with "python" from command line, but not by using "python3", but if I type "python --version" it shows "Python 3.10" which is the version I have.

After installing python from Windows Store (which opened after typing python3.exe in powershell) everything worked.

@HimbeersaftLP
Copy link
Owner

Ah, I'm guessing the issue is that even if python is not installed, windows aliases python.exe to the microsoft store link. I'll see if I can find a workaround.

@neil-hucker-seequent
Copy link

neil-hucker-seequent commented Sep 28, 2023

I had this issue and got it working. To do this I had to:
Go to Windows 11: Settings > Apps > Advanced app settings > App execution aliases to turn off the aliases for both python.exe and python3.exe.
The start.ps1 script uses Get-Command "python3.exe" so once the aliases are disabled run this command and see where it points to.

For me, I use a python.exe on my environment path instead of a python3.exe. I updated the start.ps1 to just use python.exe instead of python3.exe ie:

if (Get-Command "python.exe" -ErrorAction SilentlyContinue) {
    echo "Found Python, using it to serve the WebInspector"
    python.exe -m http.server $PORT --bind $SRV_HOST --directory $DIR 2>&1 | Out-Null

It's worth checking your firewall with the python httpserver by just running a basic web server in any directory and making sure it runs using the python on your environment path.
e.g.
python.exe -m http.server -b localhost 8080
then navigate to
localhost:8080
in webbrowser and it should show your directory listing
if you have a firewall issue it will trigger it

Since i've got other stuff running in docker on 8080 I changed it to 8081 and updated the $PORT in my start.ps1 accordingly.
Also some systems for whatever reason need 127.0.0.1 instead of localhost (probably check your windows host file), so you may need to change $SRV_HOST = "localhost" to $SRV_HOST = "127.0.0.1" in you start.ps1.

If running according the instructions and you still see nothing, it's worth checking the page list by going to
http://localhost:9222/
The site I was testing had a service worker on page 1 which wasn't returning anything and the page I needed was page 2
so I had to update
http://localhost:8081/Main.html?ws=127.0.0.1:9222/devtools/page/1
to
http://localhost:8081/Main.html?ws=127.0.0.1:9222/devtools/page/2

Improvements to the script could potentially check what happens if you execute the returned source path on Get-Command "python3.exe" and it's not able to invoke a python shell then spit out a message saying.
This was the python path found, if this opens the windows store then you may need to turn off the windows execution aliases. Maybe point to this stackoverflow page. https://stackoverflow.com/questions/58754860/cmd-opens-windows-store-when-i-type-python/58773979#58773979

It might also be worth checking python.exe as a fall back in addition to python3.exe

@HimbeersaftLP
Copy link
Owner

I wish I could just bundle a small webserver executable so you don't need any dependencies, but all the ones I found trigger various antivirus tools

@HimbeersaftLP
Copy link
Owner

@Hans-Zamorano-Matamala @JWess @neil-hucker-seequent Fixed in 77620eb
Could one of you tell me if this fix works for you?

@HimbeersaftLP
Copy link
Owner

Since there have been no comments I will assume this is fixed now. Feel free to reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants