Hey guys, I need your advice :) I am trying to deploy a chatbot application. <p>the html part works - the website is running </p> <p>however, i cannot submit any text in the chatwindow </p> <p>it works locally but not on pythonanywhere and I really dont know why </p> <p>I am using web.py for the chatwindow and ajax for updatting it </p> <p> those are my post and get
<pre>
messages = []
thread_lock = {}
session_pos = {}
counter = 0
urls = (
'/', 'Frame',
'/longpoll/([0-9]+)', 'LongPoll',
'/readall', 'ReadAll',
'/send', 'Say',
'/stop', 'Stop',
)
class LongPoll:
def GET(self, session_id):
webpy.header('Content-type', 'text/html')
thread_id = str(threading.current_thread())
if session_id not in session_pos:
session_pos[session_id] = 0
if session_pos[session_id] == len(messages):
thread_lock[thread_id] = threading.Event()
thread_lock[thread_id].clear()
thread_lock[thread_id].wait()
while session_pos[session_id] < len(messages):
msg = messages[session_pos[session_id]]
yield '<div>%s</div>\n' % msg
session_pos[session_id] += 1
class ReadAll:
def GET(self):
webpy.header('Content-type', 'text/html')
thread_id = str(threading.current_thread())
pos = 0
while True:
if pos == len(messages):
thread_lock[thread_id] = threading.Event()
thread_lock[thread_id].clear()
thread_lock[thread_id].wait()
yield messages[pos] + '\n'
pos += 1
class Say:
def POST(self):
bot = "BOT: \n"
line = webpy.input()['l']
#print "MESSAGES", messages
response = test_function(line)
response = bot + response
messages.append(line)
messages.append(response)
for thread in thread_lock:
thread_lock[thread].set()
#print "COUNTER: ", counter
return response
class Stop:
def GET(self):
os._exit(0)
class Frame:
def GET(self):
input = webpy.input()
if 'l' in input:
line = input['l']
messages.append(line)
for thread in thread_lock:
thread_lock[thread].set()
randnum = random.randint(0, 2000000000)
</pre>
and this is the html page with javascript <pre> page = """<html>
<script type="text/javascript">
$('#text').keypress(function(event) {
if (event.keyCode == '13')
sendMsg();
});
function sendMsg() {
var text = $('#text');
var msg = text.val();
$.post('/send', {'l': msg});
text.val('');
}
function stop() {
$.ajax({url: '/stop'});
$('#chat').append(' *** Stop. You may close the window. ***');
}
function getMsg() {
$.ajax({
url: '/longpoll/%d',
dataType: 'text',
type: 'get',
success: function(line) {
var you = "YOU: ";
var ymsg = you.concat(line.trim());
$('#chat').append(ymsg.trim(9));
$("#chat").attr({ scrollTop: $("#chat").attr("scrollHeight") });
setTimeout('getMsg()', 100);
}
});
}
getMsg();
</script>
</body>
<html>"""
return page % randnum
</pre>
does anybody have an idea why i cannot post anything in the chatwindow so that the submitted part is analysed by some ntlk functions defined in function.py? <p> thanks!