0

I am trying to create a simple multi browser chat web application. I thought I finished creating it. But when I try run it I get 500 status and

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Not really sure why this is occurring. I am doing this project in Flask and I am currently learning at the same time. Because I am currently learning Flask and Flask-socketio and websockets.

chatty.py:

from gevent import monkey
# Do all of the default monkey patching (calls every other function in this module.
monkey.patch_all()

from threading import Thread
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit
from time import strftime

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
socketio = SocketIO(app)
thread = None


@app.route('/')
def index():
    global thread
    if thread is None:
        #thread = Thread(target=background_thread)
        thread.start()
    return render_template('index.html')

# handle messages
@socketio.on('send message')
def handle_message(message):
    #msg = strftime("%H:%M:%S") + ': ' + str(message)
    emit('response', 
            {'data': strftime("%H:%M:%S") + ': ' + message['data']}, 
            broadcast = True)

@socketio.on('connect')
def conn():
    emit('response', {'data': 'Connected'})

if __name__ == '__main__':
    socketio.run(app)

index.html:

    <html>
    <!-- jQuery and socket.io -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            var socket = io.connect('https://' + document.domain + ':' + location.port);

            socket.on('connect', function() {
                socket.emit('', {data: 'I\'m connected!'});
            });

            socket.on('response', function(msg) {
                $('#log').append(msg.data);
            });

            $('form#broadcast').submit(function() {
                socket.emit('send message', { data: $('#msg').val()});
            })

        })
    </script>

    <form id="broadcast" method="POST">
        <input type="text" name="message" id="msg" placeholder="Enter message here...">
        <input type="submit" value="Send">
    </form>

    <h2>Chat</h2>
    <div id="log"></div>

</html>
Liondancer
  • 15,721
  • 51
  • 149
  • 255
  • In sum, you should be able to see the log message by adding `import logging; loggin.basicConfig()` to the top of your Python file (it looks like socketio doesn't properly configure a `NullHandler` for its logging). If the linked question doesn't answer your question, please edit and clarify what you still need help with and I'll re-open. – Sean Vieira Jun 23 '14 at 03:37
  • @SeanVieira I believe i fixed the issue but I can't seem to build the application I am trying to make. Basically I want to build the chat app following this http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent/page/0#comments (Only the broadcast feature) – Liondancer Jun 23 '14 at 03:52
  • I'd recommend that you try and reduce the problem to the minimum viable application that re-creates your new issue and post another question :-) – Sean Vieira Jun 23 '14 at 13:36

0 Answers0