Jump to content

Recommended Posts

Posted

 

 

Hi, friends!

My site is: apiapi.heliohost.org

My server, I use is: johnny.heliohost.org

 

I want to run a simple Python CGI script

Reading this topic (https://www.helionet.org/index/topic/29035-basic-python-script-500-internal-server-erorr/?hl=python), I decide open new one because it is not work in my case.

 

1) I create a file with simple code (tacked from link below). Using Notepad, save it as file with .cgi extension (actually I tried .py extension to) with UTF-8 encoding (actually I tried UTF-8 without BOM | ANSI encoding to).

Code I used:

#!/usr/bin/python3.6

print("Content-Type: text/html\n\n")

print("Hello")

 

======= also try =======

#!/usr/bin/python3

print("Content-Type: text/html")

print

print("Hello")

 

======= also try =======

#!/usr/bin/python3

print "Content-Type: text/html"

print

print "Hello"

 

======= also try =======

#!/usr/bin/env python

print "Content-Type: text/html"

print

print """\

<html>

<body>

<h2>Hello World!</h2>

</body>

</html>

"""

 

2) Using cPanel --> File Manager I was upload my file into /public_html/cgi-bin/ directory

 

3) I create a .htaccess file with content

AddHandler python-program .py

and upload it into /public_html/cgi-bin/ directory (actually I attempt to run my script with/without it file)

 

4) Using cPanel --> Apache Handlers I was Create an Apache Handler. I Fill next fields respectively:

Handler: python-program

Extension(s): .py

 

5) Using my browser (chrome | IE) I was try to run my script by link: apiapi.heliohost.org/cgi-bin/hello.cgi

500 server error was occupied

If my file extension is .py - just source code is shown as result

 

5) Also I try to fetch my script recuvest thru html-page:

<html>

<head>

<title>script</title>

</head>

<body bgcolor="black" text="#FF9933" link="blue" vlink="purple" alink="red">

<form action="http://apiapi.heliohost.org/cgi-bin/hello.cgi">Enter:

<input type=submit value=Go>

</form>

</body>

</html>

 

Result always is the same

 

I do not know what to do...

Dear moderators, can You, please add some Wiki-page with step-by-step instruction with content describes simple Python CGI script performing.

 

Tell my please, were can I find error log file to debug my CGI scripts

 

Tank You so-so much for Your suggestions

Posted

Delete everthing thing (.htaccess, apache handler,....)

and try use this:

 

#!/usr/bin/python

print("Content-Type: text/html")

print("")

print("Hello")

 

or this if the above doesn't work, but the above worked for my script. :

 

#!/usr/bin/python

print("Content-Type: text/html")

print()

print("Hello")

 

Remember to chmod the cgi-bin folder and the file to 755, not 644 nor 777, must be 755 to work.

If you're using Python 2.x then remove the "(" and ")"

Posted

Um. No it's not:

root@johnny [/home/palyuri/public_html/cgi-bin]# ls -l
total 4
-rw-r--r--. 1 palyuri palyuri 72 Aug 25 06:34 hello.cgi
If it was 755 it would say -rwxr-xr-x. Right now it's 644. What 644 means is owner can read and write, group can read, and other can read. What 755 means is owner can read, write and execute, group can read and execute, and other can read and execute. You can change the permission through SFTP or with the file manager in cpanel https://johnny.heliohost.org:2083/frontend/paper_lantern/filemanager/index.html
  • 4 weeks later...
Posted

The next problem is you're using dos line endings on a linux system. Cgi is very particular about line endings. The easiest way to make sure you're encoding your file correctly and using the proper line endings is to use the cpanel filemanager, and then click edit code. Either that or you can use a windows editor that knows how to output linux line endings like notepad++.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...