polling-xhr.js:157 POST https://cet-chat.herokuapp.com/socket.io/?EIO=4&transport=polling&t=NsGVGZJ&sid=2I5zXjHN7fUZN5lNAAAA 400 (BAD REQUEST) #4203
Unanswered
somesh1234567
asked this question in
Q&A
Replies: 1 comment
-
Hi! Did you check the scalability notes here: https://python-socketio.readthedocs.io/en/latest/server.html#scalability-notes? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
``Hi everybody I am trying to build a chat app using flask and socketio
The app is working fine in localserver(PORT: 5000)
but when I deploy it using gunicorn it is throing error
PROCFILE: web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
app.py:
`import os
from logging import debug
from flask import Flask, render_template, request, redirect, url_for, session
from flask_sqlalchemy import SQLAlchemy
from flask_socketio import SocketIO, join_room, leave_room, emit, rooms
from flask_session import Session
app = Flask(name)
app.debug = True
app.config['SECRET_TYPE'] = os.environ.get('SECRET')
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///chat.db"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SESSION_TYPE'] = "sqlalchemy"
db = SQLAlchemy(app)
app.config['SESSION_SQLALCHEMY'] = db
Session(app)
socketio = SocketIO(app, manage_session=False)
@app.route("/", methods=['GET', 'POST'])
def hello_world():
return render_template('index.html')
@app.route("/chat", methods=['GET', 'POST'])
def chat():
if request.method == 'POST':
username = request.form['username']
room = request.form['room']
session['username'] = username
session['room'] = room
return render_template('chat.html', session = session)
else:
if(session.get('username') is not None):
return render_template('chat.html', session = session)
else:
return redirect(url_for('index'))
@socketio.on('join', namespace='/chat')
def join(message):
room = session.get('room')
join_room(room)
emit('status', {'msg': session.get('username') + 'has enterted the room.'}, room = room)
@socketio.on('text', namespace='/chat')
def text(message):
room = session.get('room')
emit('message', {'msg': session.get('username') + ' : ' + message['msg']}, room=room)
@socketio.on('left', namespace='/chat')
def left(message):
room = session.get('room')
username = session.get('username')
leave_room(room)
session.clear()
emit('status', {'msg': username + ' has left the room.'}, room=room)
if name == 'main':
app.run()`
chat.html:
<title>Chat</title>`
CET ChatBox
Room: {{session['room']}}
<textarea id="chat" cols="70" rows="10" placeholder="No messages yet."></textarea>
SEND
Leave
Beta Was this translation helpful? Give feedback.
All reactions