georgemo Posted December 14, 2018 Posted December 14, 2018 Hello, I have just tried this script posted on this forum https://www.helionet.org/index/topic/29129-python-script-behavior/?p=132451But I get an internal error 500: Here is it: http://georgemo.heliohost.org/cgi-bin/loop.py My intention is to run this script in loop to handle bot messages. So I would also like to get module telepot implemened import telepot import time from telepot.loop import MessageLoop def handle(msg): content_type, chat_type, chat_id = telepot.glance(msg) if content_type == 'text': text = msg['text'] print(text) bot.sendMessage(chat_id = chat_id, text = "This message has been sent by heliohost") #----------------MAIN--------------------------- bot = telepot.Bot("441478801:AAFlc7xxxxxxxSSzSEm0") MessageLoop(bot, handle).run_as_thread() print('Listening ...') # Keep the program running. while 1: time.sleep(100)Thank you
wolstech Posted December 14, 2018 Posted December 14, 2018 We have a maximum runtime on scripts, so the script is timing out and producing that error. Scripts that are designed to indefinitely will hit their time limit and be killed by the server in order to help keep load down. Apache spits out a 500 error when the process its waiting on dies unexpectedly without producing output (which is what happens when python is killed). In laymans terms...it won't run here by design. We can't host scripts that are designed to be background processes.
georgemo Posted December 14, 2018 Author Posted December 14, 2018 Thank you for the answer What method would you suggest me to host a python telegram bot that is always running?
wolstech Posted December 14, 2018 Posted December 14, 2018 You need a VPS to run this. With a VPS you have your entire own virtual server, with its own operating system installation and resources, and you can use the virtual server however you want. Always-running bots like yours are a common use, as are game servers, websites that need lots of resources, etc. The bad news is that you'll have a difficult time finding such an offering for free. Even we can't afford to offer them free: https://heliohost.org/vps For what you're doing, the cheapest $4/month plan would be plenty.
Krydos Posted December 14, 2018 Posted December 14, 2018 As long as the scripts don't cause a lot of load they should be fine. If you read the link that you posted there is actually 3 scripts. One to start the script that you access with a browser, one to end the script that you access with a browser, and a loop script that you don't access in a browser. If you run the loop.py directly you'll get a 500 error when you browser closes, times out, or the http process kills it, etc. Also I don't see a shebang on your script that you posted. Did you just omit that?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now