SOLVED Python Script not running on cPanel

Vasanthjan

Member
Mar 8, 2017
14
0
1
India
cPanel Access Level
Root Administrator
On new cPanel version I'm not able to run the python script getting Internal Server Error

Files on cPanel to preview.

Screenshot_1.png

Getting below error message on domain.com/cgi-bin/sample.py

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 at [EMAIL][email protected][/EMAIL] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Errors on cPanel:

AH01xx5: attempt to invoke directory as script: /home/scriptsbrownarc/public_html/cgi-bin/, referer: domain.com/

Apache Handler also available:

Screenshot_2.png

Kindly help me out to resolve this error to run python and perl scripts on cPanel.

SSH Output:

Code:
[[email protected] ~]$ whereis python
python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7
[[email protected] ~]$
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello,

The image you provided shows the Python script stored outside of the cgi-bin directory. Can you check to see if it opens correctly when moved within the cgi-bin directory?

Thank you.
 

Kent Brockman

Well-Known Member
PartnerNOC
Jan 20, 2008
1,315
70
178
Buenos Aires, Argentina
cPanel Access Level
Root Administrator
Hello @cPanelMichael sorry for bumping, but I have the exact same issue here. Same Apache handler, same .py script, and it is throwing the same "internal server error" in the browser no matter if I put the script inside cgi-bin or not.

Content of test.py:
Code:
#!/usr/bin/python
print "Content-type: text/html\n"
print "How to run Python scripts in cPanel"
Content of .htaccess:
Code:
AddHandler cgi-script .py
test.py has permission 777

And on the terminal:
Code:
#  whereis python
python: /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz

# /usr/bin/python cgi-bin/test.py
Content-type: text/html

How to run Python scripts in cPanel
So, it works in the console but not in the browser.

Any advice?
Thanks in advance! :)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hi @Kent Brockman,

I'm glad to see that helped. I've marked this thread as solved.

Thank you.
 

ewurama

Registered
Jun 22, 2018
1
0
0
Ghana
cPanel Access Level
Root Administrator
Hello, I am having the same problem solved. However, I changed permission of my python main script to 0755 from 0644. But still not working.
I have activated a virtual environment for python 3.6 but when i type whereispython, it returns path for python 2.6

Kindly assist