Jump to content


Photo

Python script in cgi-bin is not returning anything!

python

  • This topic is locked This topic is locked
4 replies to this topic

#1 alaister

alaister

    Newbie

  • Members
  • 5 posts
  • Gender:Male
  • Location:Hong Kong
  • Interests:Coding

Posted 21 February 2021 - 03:40 AM

This script is copied from this tutorial: https://wiki.helione...als/discord-bot
My script: https://alaister.net...in/start_bot.py

#!/usr/bin/python3.7

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

import os, subprocess, signal

counter = 0
p = subprocess.Popen(['ps', '-u', 'lj'], stdout=subprocess.PIPE)
out, err = p.communicate()

for line in out.splitlines():
  if 'alaisterbot.py'.encode('utf-8') in line:
    counter += 1
    print("Discord bot is already online!")

if counter == 0:
  subprocess.Popen("/home/lj/alaisterbot.py")
  print("Starting Discord bot...")

When I open the file in the browser, it doesn't even return anything. No errors. Just a blank white page. I expect it shows 'starting discord bot' or 'bot is already online'. The discord bot is also offline after running this. Please help.

Server: Tommy
cPanel username: lj


Edited by alaister, 22 February 2021 - 02:24 AM.


#2 Luigi123

Luigi123

    Rank X Member

  • Moderators
  • 2,737 posts
  • Gender:Male
  • Location:Winnipeg, Manitoba, Canada

Posted 21 February 2021 - 03:45 PM

Did you make sure that you have set up the permissions to 755 for every .py files?
Posted ImagePosted ImagePosted Image
Posted ImagePosted ImagePosted Image

#3 alaister

alaister

    Newbie

  • Members
  • 5 posts
  • Gender:Male
  • Location:Hong Kong
  • Interests:Coding

Posted 22 February 2021 - 02:26 AM

Yes, I have already set the permissions of start_bot.py, stop_bot.py, and alaisterbot.py to 755. I have also checked that no errors are reported by cPanel.

 

Edit: errors found!

My file really exists: https://imgur.com/MVk9YkW

[Mon Feb 22 02:22:51.470823 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.470442 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.470252 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.470002 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.469874 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.469544 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.469397 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:51.469079 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.093525 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.093227 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.093049 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.092815 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.092698 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.092451 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.092313 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 02:22:35.092006 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.489075 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488793 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488651 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488444 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488353 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488183 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.488075 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py
[Mon Feb 22 01:02:11.487820 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.470823 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.470442 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.470252 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.470002 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.469874 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.469544 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.469397 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:51.469079 2021] [cgi:error] [pid 58144] [client 162.158.179.21:29438] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.093525 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.093227 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.093049 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.092815 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.092698 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.092451 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.092313 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 02:22:35.092006 2021] [cgi:error] [pid 60240] [client 162.158.179.21:11462] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.489075 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215: FileNotFoundError: [Errno 2] No such file or directory: '/home/lj/alaisterbot.py': '/home/lj/alaisterbot.py': /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488793 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     raise child_exception_type(errno_num, err_msg, err_filename): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488651 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488444 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     restore_signals, start_new_session): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488353 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 775, in __init__: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488183 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:     subprocess.Popen("/home/lj/alaisterbot.py"): /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.488075 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215:   File "/home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py", line 17, in <module>: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

[Mon Feb 22 01:02:11.487820 2021] [cgi:error] [pid 41533] [client 172.68.254.39:15194] AH01215: Traceback (most recent call last):: /home/lj/public_html/domains/alaister.net/cgi-bin/start_bot.py

 


Edited by alaister, 22 February 2021 - 02:38 AM.


#4 alaister

alaister

    Newbie

  • Members
  • 5 posts
  • Gender:Male
  • Location:Hong Kong
  • Interests:Coding

Posted 22 February 2021 - 08:36 AM

I solved the problem after reading this old discussion:

https://ubuntuforums.../t-1751674.html

 

I must change the script from CRLF to LF.



#5 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 13,412 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 22 February 2021 - 12:25 PM

Yep, line endings will cause all sorts of weird issues with Python. You need to make sure they're unix style :)


Please do not PM me for support. Posting on our forums lets all of us learn.
Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...






Also tagged with one or more of these keywords: python

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users