Re: Coming from Perl

2007-09-17 Thread Amer Neely
Bryan Olson wrote:
 Amer Neely wrote:
 I don't have shell access but I can run 'which python' from a Perl 
 script, and I will try the different shebang line you suggested.
 
 And after trying it, Amer Neely reported:
 
 I tried `which python` and `whereis python` and got 0 back as a 
 result. So it seems Python is not installed at all.
 
 Probably right, but just to be thorough...  Since you do not
 have shell access, I'm guessing you are running these within
 a Perl cgi script, and getting the results via a browser. Is
 that right?

Yes.
 
 Can you backtick other commands? What do you get if you run
 `which perl` the same way? How about `whoami`, `whereis sh`,
 and `which nosuchthingas5748614`? Can you list /, /bin and
 /usr/bin?

I just looked at my code and tried something else:
@SysCmd=which python;
system(@SysCmd);

and it came back
/usr/local/bin/python

 
 How did you learn that this system could run your Perl
 scripts? Can that source give us anything to go on here?
 If Python is not installed, do you have some avenue for
 requesting it?
 
 We're down to long shots. Still, hosts that support Perl
 but will not support Python are getting to be the rare.
 
 

I've asked my host to put in a request for it.

So it seems python IS installed, but not where I thought it was.

I just tried my script with the new path, but still got a 500 server 
error. Can I trap errors to a file locally?

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-16 Thread Amer Neely
Paddy wrote:
 On Sep 13, 1:30 am, Amer Neely [EMAIL PROTECTED] wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 Hi Amer,
 Just as an aside, you might find this helpful:
   http://wiki.python.org/moin/PerlPhrasebook
 It has perl code with python equivalents/notes.
 

Hello Paddy,
Thanks for that link - it does look quite useful.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl - SOLVED

2007-09-15 Thread Amer Neely
I V wrote:
 On Thu, 13 Sep 2007 23:49:32 -0400, Amer Neely wrote:
 In trying to track down why this script would not run on my host, it has
 to come to light that Python is installed, however the Apache module is
 not. So, short story is - I was flogging a dead horse.
 
 Which Apache module? You don't need any special modules (just the regular 
 CGI one) to use python in a CGI script.

That is an interesting observation. It does run under my Apache + Win2K 
at home, with no special configuration by me. All I'm going on is what 
the techs told me.

So, you think it may be something else? I've changed and even eliminated 
the end-of-line chars in my print statements.

Another poster (Bryan Olson) has suggested a few things to try as well 
so I will try those. I don't have shell access though, so the best I can 
do is execute shell commands from a Perl script.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-15 Thread Amer Neely
Bryan Olson wrote:
 Amer Neely wrote:
 This seems to indicate that maybe my host needs to configure Apache to 
 run python scripts? But I didn't need to do anything with mine.
 
 Another possibility: If it works on Windows but not Unix, check
 the end-of-line characters. Windows ends each line with the two
 character sequence carriage-return + newline, which in Python
 is \r\n. Unix uses newline alone, \n.
 
 Most Unixies will choke on a #! line with a carriage return.
 The Python interpreter will accept source files with either
 end-of-line on either system, but of course you'll not get
 that far unless the operating system respects the shebang line.
 
 Maybe you already checked that. Hmmm...other possiblities...
 
 Do you have shell access? Can you executing it directly from
 the shell? Do you get a Python error, or some other?
 
 Did you:  chmod ugo+rx yourscript
 
 Is Python in /usr/bin? What does which python say?
 
 Generally, most experts seem to prefer:
 
 #!/usr/bin/env python
 
 You might try changing the the extension of your script from .py
 to .cgi. Windows uses the .py to choose the executable, but Unix
 does not care; it used the shebang line.
 
 

Hmmm. These are interesting suggestions. Especially in light of a new 
wrinkle pointed out by [IV]. That being the script runs fine under my 
Apache at home with no special modules loaded.

I don't have shell access but I can run 'which python' from a Perl 
script, and I will try the different shebang line you suggested.

Thanks for the suggestions.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-15 Thread Amer Neely
Bryan Olson wrote:
 Amer Neely wrote:
 This seems to indicate that maybe my host needs to configure Apache to 
 run python scripts? But I didn't need to do anything with mine.
 
 Another possibility: If it works on Windows but not Unix, check
 the end-of-line characters. Windows ends each line with the two
 character sequence carriage-return + newline, which in Python
 is \r\n. Unix uses newline alone, \n.
 
 Most Unixies will choke on a #! line with a carriage return.
 The Python interpreter will accept source files with either
 end-of-line on either system, but of course you'll not get
 that far unless the operating system respects the shebang line.
 
 Maybe you already checked that. Hmmm...other possiblities...
 
 Do you have shell access? Can you executing it directly from
 the shell? Do you get a Python error, or some other?
 
 Did you:  chmod ugo+rx yourscript
 
 Is Python in /usr/bin? What does which python say?
 
 Generally, most experts seem to prefer:
 
 #!/usr/bin/env python
 
 You might try changing the the extension of your script from .py
 to .cgi. Windows uses the .py to choose the executable, but Unix
 does not care; it used the shebang line.
 
 

I tried `which python` and `whereis python` and got 0 back as a result. 
So it seems Python is not installed at all.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
TheFlyingDutchman wrote:
 On Sep 12, 5:30 pm, Amer Neely [EMAIL PROTECTED] wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 --
 Amer Neely
 w:www.webmechanic.softouch.on.ca/
 Perl | MySQL programming for all data entry forms.
 Others make web sites. We make web sites work!
 
 I am not sure if this is what you are looking for, but Python has a
 special string with 3 quotes that I believe duplicates part of the
 functionality of a here document:
 
 myHmtlHeader = 
 head attribute = abc
 titleMy Page/title
 /head
 
 
 print myHtmlHeader
 
 
 outputs:
 
 
 head attribute=abc
 titleMy Page/title
 /head
 

Well, I have checked everything I can but I'm getting '500 Internal 
Server Error'. The log files aren't helpful:
[Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py

I can't even get it to run on my home PC running Apache + Win2K. Same error.

My script:
#!/usr/bin/python
import cgitb; cgitb.enable(display=0, logdir=.)
import sys
sys.stderr = sys.stdout
print Content-Type: text/html
print

print 
html
body
div align=centerfont style=font-family:verdana; size:18pxHello 
from Python/font/div
br
Goodbye.
/body
/html


-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Amer Neely wrote:
 TheFlyingDutchman wrote:
 On Sep 12, 5:30 pm, Amer Neely [EMAIL PROTECTED] wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 -- 
 Amer Neely
 w:www.webmechanic.softouch.on.ca/
 Perl | MySQL programming for all data entry forms.
 Others make web sites. We make web sites work!

 I am not sure if this is what you are looking for, but Python has a
 special string with 3 quotes that I believe duplicates part of the
 functionality of a here document:

 myHmtlHeader = 
 head attribute = abc
 titleMy Page/title
 /head
 

 print myHtmlHeader


 outputs:


 head attribute=abc
 titleMy Page/title
 /head

 
 Well, I have checked everything I can but I'm getting '500 Internal 
 Server Error'. The log files aren't helpful:
 [Thu Sep 13 03:43:00 2007] [error] [client 24.235.184.39] Premature end 
 of script headers: /home/softouch/public_html/cgi-bin/scratch/hello.py
 
 I can't even get it to run on my home PC running Apache + Win2K. Same 
 error.
 
 My script:
 #!/usr/bin/python
 import cgitb; cgitb.enable(display=0, logdir=.)
 import sys
 sys.stderr = sys.stdout
 print Content-Type: text/html
 print
 
 print 
 html
 body
 div align=centerfont style=font-family:verdana; size:18pxHello 
 from Python/font/div
 br
 Goodbye.
 /body
 /html
 
 

I should have added that it runs from the command line OK.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Ben Finney wrote:
 Amer Neely [EMAIL PROTECTED] writes:
 
 Well, I have checked everything I can but I'm getting '500 Internal
 Server Error'.
 
 This is the HTTP response code saying that the program that should
 have served the response document instead exited with an error.
 
 To debug, you should first run the program (or at least the part that
 you're trying to implement) *outside* the context of a web server. Do
 it at a command line, and any errors will show up as exception
 tracebacks.
 
 Only when you have something that performs correctly outside a web
 server context should you consider how to wrap it in that new
 (harder-to-debug) context.
 

That is where I'm stuck. It runs fine on my home computer, but I don't 
have shell access to my hosted site.

Can you or anyone see anything in the posted code that might be the 
cause? Why is it so much harder to debug? There is no syntax error that 
I can tell. I've set the file permissions to rwxr-xr-x. I've printed the 
correct content type. It's a simple print statement, as per several 
examples I've seen.

Is it an Apache thing? I've not seen any mention in the documentation on 
that.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Richie Hindle wrote:
 [Amer]
 Can you or anyone see anything in the posted code that might be the 
 cause?
 
 #!/usr/bin/python
 import cgitb; cgitb.enable(display=0, logdir=.)
 import sys
 sys.stderr = sys.stdout
 print Content-Type: text/html
 print
 
 My guess would be that you don't have cgitb in your server environment, or
 that you have a bogus one.  Rearrange things like this:
 
 #!/usr/bin/python
 print Content-Type: text/html
 print
 import sys
 sys.stderr = sys.stdout
 import cgitb; cgitb.enable(display=0, logdir=.)
 

Nope. Same error. Is cgitb not in the standard distribution? Is it 
needed to print HTML?

On my home PC I changed the Apache error logging to 'debug' and got this 
nugget:
[Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
cannot find the file specified.  : couldn't create child process: 
720002: hello.py

I suspect it would be similar on my hosting server. Is this saying it 
can't find hello.py or one of the modules?

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Richie Hindle wrote:
 [Amer]
 #!/usr/bin/python
 [...] On my home PC [...]
 [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
 cannot find the file specified.
 
 That's because on your home PC Python is somewhere like
 C:\Python25\python.exe, not /usr/bin/python.
 
 Are you sure /usr/bin/python is correct for your hosting environment?
 

It's my understanding that the Windows shell doesn't pay much attention 
to the shebang line if the file type is associated with the proper 
application.

But I tried your suggestion and got the same results.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Amer Neely wrote:
 Richie Hindle wrote:
 [Amer]
 #!/usr/bin/python
 [...] On my home PC [...]
 [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
 cannot find the file specified.

 That's because on your home PC Python is somewhere like
 C:\Python25\python.exe, not /usr/bin/python.

 Are you sure /usr/bin/python is correct for your hosting environment?

 
 It's my understanding that the Windows shell doesn't pay much attention 
 to the shebang line if the file type is associated with the proper 
 application.
 
 But I tried your suggestion and got the same results.
 

My BAD! I changed the shebang all right, but entered a typo. With the 
correct path it did work just fine.

So, perhaps the path to python on my host is wrong? I got that one right 
from the techs.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-13 Thread Amer Neely
Tim Golden wrote:
 Amer Neely wrote:
 Richie Hindle wrote:
 [Amer]
 #!/usr/bin/python
 [...] On my home PC [...]
 [Thu Sep 13 04:16:03 2007] [error] [client 0.0.0.0] (OS 2)The system 
 cannot find the file specified.
 That's because on your home PC Python is somewhere like
 C:\Python25\python.exe, not /usr/bin/python.

 Are you sure /usr/bin/python is correct for your hosting environment?


 It's my understanding that the Windows shell doesn't pay much 
 attention to the shebang line if the file type is associated with the 
 proper application.

 But I tried your suggestion and got the same results.
 

See my reply to this post - I had a typo in the shebang line and it now 
works on my home PC.

 The Windows shell doesn't, but Apache does. (Haven't followed
 this thread closely, but I seem to remember it has to do with
 running CGI scripts).

This seems to indicate that maybe my host needs to configure Apache to 
run python scripts? But I didn't need to do anything with mine.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl - SOLVED

2007-09-13 Thread Amer Neely
Amer Neely wrote:
 I'm a complete newbie with Python, but have several years experience 
 with Perl in a web environment.
 
 A question I have, if someone here is familiar with Perl, does Python 
 have something like Perl's 'here document'? I've just searched and read 
 some postings on generating HTML but they all seem to refer to various 
 template utilities. Is this the only way, or am I missing something? I'm 
 used to generating X/HTML by hand, which makes the here document in Perl 
 ideal for me. Also, many times a client already existing HTML code that 
 I can use in a script.
 

In trying to track down why this script would not run on my host, it has 
to come to light that Python is installed, however the Apache module is 
not. So, short story is - I was flogging a dead horse.

Sorry for raising a non-issue folks.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Coming from Perl

2007-09-12 Thread Amer Neely
I'm a complete newbie with Python, but have several years experience 
with Perl in a web environment.

A question I have, if someone here is familiar with Perl, does Python 
have something like Perl's 'here document'? I've just searched and read 
some postings on generating HTML but they all seem to refer to various 
template utilities. Is this the only way, or am I missing something? I'm 
used to generating X/HTML by hand, which makes the here document in Perl 
ideal for me. Also, many times a client already existing HTML code that 
I can use in a script.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-12 Thread Amer Neely
Ben Finney wrote:
 Amer Neely [EMAIL PROTECTED] writes:
 
 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'?
 
 I'm not sure exactly what behaviour you want, but Python accepts
 literal strings to be triple-quoted (i.e. delimited by  pairs or
 ''' pairs), which allows you to freely use literal line feed and quote
 characters inside that string.
 
 URL:http://docs.python.org/ref/strings.html
 

I saw that and I guess that is the closest thing. In Perl I can do ..

print EndHTML;
html
body
Hello
/body
/html
EndHTML

In this case 'EndHTML' is a label, and I'm telling perl to print 
everything as is up to that label.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from Perl

2007-09-12 Thread Amer Neely
TheFlyingDutchman wrote:
 On Sep 12, 5:30 pm, Amer Neely [EMAIL PROTECTED] wrote:
 I'm a complete newbie with Python, but have several years experience
 with Perl in a web environment.

 A question I have, if someone here is familiar with Perl, does Python
 have something like Perl's 'here document'? I've just searched and read
 some postings on generating HTML but they all seem to refer to various
 template utilities. Is this the only way, or am I missing something? I'm
 used to generating X/HTML by hand, which makes the here document in Perl
 ideal for me. Also, many times a client already existing HTML code that
 I can use in a script.

 --
 Amer Neely
 w:www.webmechanic.softouch.on.ca/
 Perl | MySQL programming for all data entry forms.
 Others make web sites. We make web sites work!
 
 I am not sure if this is what you are looking for, but Python has a
 special string with 3 quotes that I believe duplicates part of the
 functionality of a here document:
 
 myHmtlHeader = 
 head attribute = abc
 titleMy Page/title
 /head
 
 
 print myHtmlHeader
 
 
 outputs:
 
 
 head attribute=abc
 titleMy Page/title
 /head
 

Yep, I think that is the way I will have to go. Thanks.

-- 
Amer Neely
w: www.webmechanic.softouch.on.ca/
Perl | MySQL programming for all data entry forms.
Others make web sites. We make web sites work!
-- 
http://mail.python.org/mailman/listinfo/python-list