I know.. Python Help again, but its not working..

nate_bro

New Member
Messages
6
Reaction score
0
Points
0
Ok, I have never ran python on a server, but i thought i would give it a try, but with no luck.


its driveing me crazzy, i got the permissions right... cmod 755 DUH!


got the .htaccess right? i think, its what they said before would work..

AddHandler cgi-script .cgi .py .pl .pm


PERL is working fine as ALWAYS, but not this darn Python...
Code:
#!/usr/bin/python
#!/usr/bin/env python
 
print "Content-Type: text/html \r\n\r\n" 
print "Hello, World!"


Code:
[B]Internal Server Error[/B]
 
The server encountered an internal error or misconfiguration and was unable to complete your request.
 
Please contact the server administrator, webmaster@setapartcomputersolutions.pcriot.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
 
More information about this error may be available in the server error log.
 
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

any help in the right direction would be great! THNX
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Only the first shebang will have any affect, and it needs to be on the first line. Remember, "#!" is actually a magic number. Any shebangs not on the first line are just comments.

Also note that you typically don't need to print CRLF. LF will be translated to CRLF.
 
Last edited:

nate_bro

New Member
Messages
6
Reaction score
0
Points
0
well...

i have been all over this darn forum, and it is still not working, also, the code i have there is from here: http://forums.x10hosting.com/progra...er-how-do-i-get-running-starting-scratch.html

I have tried evry shebang i can find, but with no luck.


I edited the .htaccess evry way someone said, i did 755, tried 50 scripts nothing is working yet... gerrrr!


I know this is going to be some stupid simple thing, it always is.
thanks for your help...
 

gillwill

New Member
Messages
9
Reaction score
0
Points
0
Have you tried running it from cgi-bin folder first to see if it works from there?

Can you cut & paste your htaccess contents here. Maybe some typo in there.
 
Last edited:

nate_bro

New Member
Messages
6
Reaction score
0
Points
0
No, it will not run anywhere!

I can run a PERL script anywhere as a CGI

but Python will not work,

On my PERL i have
#!/usr/bin/perl -w "Works fine"

and python
#!/usr/bin/python "Error"

whats wrong here?
thnx


also, i take the same cgi file, cmod it, write as a PERL script, run it, it dose fine. but then I past in the Python, and it gets an error.
 
Last edited:

gillwill

New Member
Messages
9
Reaction score
0
Points
0
Code:
#!/usr/bin/python
#!/usr/bin/env python
 
print "Content-Type: text/html \r\n\r\n" 
print "Hello, World!"


Wow, that is bizarre, as when I copy & pasted your code it works for me whether in cgi-bin folder or elsewhere.

Hopefully, someone more experienced than I in here will come up with something.

-gil
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Did you remove the blank line at the start of the script? Is "Options +ExecCGI" included in .htaccess?
 

nate_bro

New Member
Messages
6
Reaction score
0
Points
0
If i write a script say, myscript.cgi and write it in PERL and it works, then just replace the PERL code with the Phython it should work right??

this is my .htaccess
the server is processing it, so the .htaccess should not be the prob right? otherwise it would just display in plain text...
Code:
# -FrontPage-
  <Limit GET POST>
  order deny,allow
  deny from all
  allow from all
  </Limit>
  <Limit PUT DELETE>
  order deny,allow
  deny from all
  </Limit>
  AuthName setapartcomputersolutions.pcriot.com
  AuthUserFile /home/natebro/public_html/_vti_pvt/service.pwd
  AuthGroupFile /home/natebro/public_html/_vti_pvt/service.grp
  AddHandler cgi-script .cgi .py .pl .pm
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
That should be sufficient. Chances are there's something wrong with the script, such as a unicode byte-order mark (BOM). Please post a zipped copy of the script as an attachment.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Why is it called myscript.cgi ?

Try renaming it myscript.py

Lastly, did you use the FileManager to write it, or did you upload it from a Windows machine?
 

nate_bro

New Member
Messages
6
Reaction score
0
Points
0
well, i tried .cgi and .py both had no luck.

I used the FileManager to write it, and I uploaded it from 3 FTP programs from a Windows machine. I know what your getting at, becouse i had that prob the first time i was uploading a PERL script before, I don't think thats it.

I was thinking it was the shebang path, but i really am at a loss here

Thanks
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It's a file coding issue. myscript.cgi uses MS-DOS line endings ("\x0D\x0A"), while the server uses Unix line endings ("\x0A"). If you're using FTP, upload it to the server using ASCII transfer mode.

From the Python tutorial, 2.2.2. "Executable Python Scripts":
On some platforms, this first line must end with a Unix-style line ending ('\n'), not a Windows ('\r\n') line ending.
This is a system limitation, rather than a python limitation, as the system needs to be able to recognize the end of the shebang line in order to invoke the command. This is part of the responsibility of the exec() family of functions, in particular sys_execve() on Linux systems, which is part of the kernel.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
1. Write it from scratch in the FileManager
2. Forget the shebang lines
3. Name it whatever.py
4. Your htaccess file seems ok.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
2. Forget the shebang lines
We're using mod_cgi, not mod_python, so the shebang line is mandatory. Without the shebang line, mod_cgi will run the script as a shell script, causing an internal server error because almost no python script is a valid shell script, and those that are valid won't work as CGI scripts.

3. Name it whatever.py

File extensions don't matter to mod_cgi. When it comes to scripts, file extensions only matter for mod_mime's "AddType" and "AddHandler" directives. If we were using mod_python, the '.py' extension would matter because we'd be using an "AddHandler" directive. With mod_cgi, you can give a file any file extension you want, as long as it's listed in an "AddHandler cgi-script ..." directive and the shebang line is correct. You could even give a python script a '.pl' extension. It would be confusing to people, but it wouldn't matter to mod_cgi.
 
Top