[Tutor] localhosting

Alan Gauld alan.gauld at yahoo.co.uk
Thu Sep 6 18:54:39 EDT 2018


On 06/09/18 20:09, Roger Lea Scherer wrote:

> I removed the "3" in "python3" and it works; along with moving the "www"
> folder to where python resides. Thanks for the help.

That may appear to work but I suspect its just hiding the real issue
which is about setting the correct path values.

Did you try using the py launcher that Mats suggested.
I think that is the officially recommended solution
for these issues on Windows...

Anyway...
> So it appears the local host is running correctly, 

I assume you mean some kind of web server running
on the localhost network port? ie 127.0.0.1?

> print("Hello World")
> 
> Chrome does not render and I get an error message in PowerShell:
> 127.0.0.1 - - [06/Sep/2018 11:22:46] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
> 127.0.0.1 - - [06/Sep/2018 11:22:46] command:
> C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
> C:\Users\Roger\documents\roger\python\www\cgi-bin\hello.py ""
> 127.0.0.1 - - [06/Sep/2018 11:22:46] b'  File
> "C:\\Users\\Roger\\documents\\roger\\python\\www\\cgi-bin\\hello.py", line
> 1\r\n    print "<html>"\r\n                 ^\r\nSyntaxError: Missing
> parentheses in call to \'print\'. Did you mean print("<html>")?\r\n'
> 127.0.0.1 - - [06/Sep/2018 11:22:46] CGI script exit status 0x1

Are you sure that the file hello.py in cgi-bin only
contains the one line? It looks like you may have a
default one with Python 2.7 code in it?



> 1. Why does the one file cause an error in PowerShell (and Anaconda
> actually) when it seems to be the same as the other file which appears to
> run with no error, but just not render? and,

Neither of them output valid html, so I guess that's
why they don't render. The first doesn't appear to be
the hello.py that you think it is - try opening it
in your text editor to check (using the exact path
that the log message uses).

> 2. What am I missing: why won't it render since the instructions I have at
> the very beginning of this email say, basically, this is all I have to do
> to get it to render?

Maybe your instructions are wrong? Maybe they are for Python 2 and you
are running Python 3?

You might find it helpful to read the section on writing web
applications in my tutorial:

http://www.alan-g.me.uk/l2p2/index.htm

Look in the Applications section and read the Web Server
topic for a short example of how to use the basic http.server

> I know this second question is maybe a little bit outside this forum, 

Nope, explanations of why things go wrong are entirely apropos

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list