Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED Python Script not running on cPanel

Discussion in 'General Discussion' started by Vasanthjan, Aug 14, 2017.

Tags:
  1. Vasanthjan

    Vasanthjan Member

    Joined:
    Mar 8, 2017
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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]webmaster@example.com[/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:
    [scriptsbrownarc@panda ~]$ whereis python
    python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7
    [scriptsbrownarc@panda ~]$
    
     
    #1 Vasanthjan, Aug 14, 2017
    Last edited by a moderator: Aug 10, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,827
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,187
    Likes Received:
    8
    Trophy Points:
    168
    Location:
    Buenos Aires, Argentina
    cPanel Access Level:
    Root Administrator
    Twitter:
    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! :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,827
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Kent Brockman,

    This entry is not required in the .htaccess file.

    Permissions should be set to 0755 instead of 0777. Using 0777 permissions will lead to the error message you reported. Let me know if changing the permissions to 0755 helps.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,187
    Likes Received:
    8
    Trophy Points:
    168
    Location:
    Buenos Aires, Argentina
    cPanel Access Level:
    Root Administrator
    Twitter:
    It worked great! Thanks!!!!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    cPanelMichael likes this.
  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,827
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi @Kent Brockman,

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

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice