sb7064 Posted August 18, 2020 Posted August 18, 2020 (edited) My python bot in cgi-bin occurs internal server error but i can't figure out what is wrong.I set permission as 755, and uploaded all lib files at same folder.It works on my pc and online python IDE(lepi) but not on here. *this code also causes same error #!/usr/bin/python3.7 print("test") This is my bot code #!/usr/bin/python3.7 import asyncio import discord import time from parse import * client = discord.Client() remCount = 0 remHList = [] remMList = [] remTList = [] channelList = [] isRemindRunning = 0 # 생성된 토큰을 입력해준다. token = DISCORD_TOKEN # 봇이 구동되었을 때 보여지는 코드 @client.event async def on_ready(): print("다음으로 로그인합니다") print(client.user.name) print(client.user.id) print("================") await remind() # 봇이 특정 메세지를 받고 인식하는 코드 @client.event async def on_message(message): # 메세지를 보낸 사람이 봇일 경우 무시한다 if message.author.bot: return None if message.content.startswith('!알림'): global remCount global isRemindRunning print(message.content) text = parse("!알림 {}:{} {}",message.content) print(text) channel = message.channel hour = (int(text[0])-9)%24 remHList.append(hour) remMList.append(int(text[1])) remTList.append(text[2]) channelList.append(channel) remCount = remCount+1 now = time.localtime() await channel.send('Reminds '+text[2]+' at '+text[0]+':'+text[1]) elif message.content.startswith('!예약'): print(message.content) text = parse("!예약 {}:{} {}",message.content) print(text) channel = message.channel hour = (int(text[0])-9)%24 remHList.append(hour) remMList.append(int(text[1])) remTList.append(text[2]) channelList.append(channel) remCount = remCount+1 await channel.send('Reminds '+text[2]+' at '+text[0]+':'+text[1]) return elif message.content.startswith('!remind'): print(message.content) text = parse("!remind {}:{} {}",message.content) print(text) channel = message.channel hour = (int(text[0])-9)%24 remHList.append(hour) remMList.append(int(text[1])) remTList.append(text[2]) channelList.append(channel) remCount = remCount+1 await channel.send('Reminds '+text[2]+' at '+text[0]+':'+text[1]) return elif message.content.startswith('!목록'): if remCount == 0: await message.channel.send('Reminder list is empty') return text = "" for i in range(0,remCount): text = text+str(i+1)+': '+ remTList[i]+' at '+str((remHList[i]+9)%24)+':'+str(remMList[i])+'\n' await message.channel.send(text) elif message.content.startswith('!list'): if remCount == 0: await message.channel.send('Reminder list is empty') return text = "" for i in range(0,remCount): text = text+str(i+1)+': '+ remTList[i]+' at '+str((remHList[i]+9)%24)+':'+str(remMList[i])+'\n' await message.channel.send(text) elif message.content.startswith('!clear'): for i in range(0,remCount): remHList.pop(i) remMList.pop(i) remTList.pop(i) channelList.pop(i) remCount = 0 await message.channel.send('All Reminders deleted.') elif message.content.startswith('!초기화'): for i in range(0,remCount): remHList.pop(i) remMList.pop(i) remTList.pop(i) channelList.pop(i) remCount = 0 await message.channel.send('모든 리마인더 삭제 완료') @client.event async def remind(): global remCount global isRemindRunning while True: await asyncio.sleep(10) now = time.localtime() print('Checking Reminders at '+str(now.tm_hour)+':'+str(now.tm_min)+':'+str(now.tm_sec)) for i in range(0,remCount): if now.tm_hour==remHList[i] and now.tm_min==remMList[i]: await channelList[i].send(remTList[i],tts=True) print('Sent reminder '+remTList[i]) remHList.pop(i) remMList.pop(i) remTList.pop(i) channelList.pop(i) remCount = remCount-1 break client.run(token) Edited August 18, 2020 by sb7064 1
Krydos Posted August 18, 2020 Posted August 18, 2020 My python bot in cgi-bin occurs internal server error but i can't figure out what is wrong.I set permission as 755, and uploaded all lib files at same folder.It works on my pc and online python IDE(lepi) but not on here. *this code also causes same error#!/usr/bin/python3.7 print("test") CGI is different from running python scripts on the command line, because you have to output a header. Without a content-type header your script will always give a 500 error. Try this code: #!/usr/bin/python3.7 print("Content-Type: text/html\n\n") print("HelioHost rules!")
sb7064 Posted August 18, 2020 Author Posted August 18, 2020 I tried but It not works too. My python bot in cgi-bin occurs internal server error but i can't figure out what is wrong.I set permission as 755, and uploaded all lib files at same folder.It works on my pc and online python IDE(lepi) but not on here. *this code also causes same error #!/usr/bin/python3.7 print("test") CGI is different from running python scripts on the command line, because you have to output a header. Without a content-type header your script will always give a 500 error. Try this code: #!/usr/bin/python3.7 print("Content-Type: text/html\n\n") print("HelioHost rules!")
Krydos Posted August 18, 2020 Posted August 18, 2020 The next problem I see is your test.py file has Dos line endings. This is usually caused by using a Windows editor, such as notepad, that doesn't understand line endings, and then uploading the file to the server. This is a Linux server, so you need to have Linux line endings. The easiest way to accomplish this is to create the file through the cpanel file editor, and copy/paste your code in. If you prefer to use an editor on your Windows computer and then upload through FTP you'll need to get an editor that understands line endings. I've never used it myself, but I've heard that Notepad++ can do this.
Recommended Posts